Maven tips and tricks

Tuesday, May 30, 2017 | 3 minute read | Updated at Tuesday, Mar 18, 2025

git-branch-renamer-maven-plugin

When working with many feature/release/bugfix/hotfix branches, it is a bad idea to start changing the pom version as this will create merge conflicts using pull request. this plugin allows you to keep in ALL branches the same pom version for all your projects, for example MASTER-SNAPSHOT the version will be derived from branch name automagically 🙂

git-branch-renamer-maven-plugin allow you to keep in ALL branches the same pom version for all your projects: for example MASTER-SNAPSHOT and never change it again.

the project version will be derived from branch name automatically when running in your continuous integration server.

branch name feature/xxxx

  • <version>xxxx-SNAPSHOT</version> (default)
  • <version>xxxx</version> (release = true)
  • <version>0-xxxx-SNAPSHOT</version> (forceNumericalVersion = true)
  • <version>feature-xxxx-SNAPSHOT</version> (filterOutBranchQualifier = false)

The project is hosted at GitHub https://github.com/cedricwalter/git-branch-renamer-maven-plugin

Fetching artifact programmatically through REST/API in Nexus 3.x

There is so many case where it is desirable to pull down artifact from Sonatype #Nexus using REST API, unfortunately #Nexus 3.x Rest API are still under development…

Some use cases in Nexus 2.x:

  • You have a script that uses #REST call to pull down the LATEST maven artifacts every night from Nexus and deploys them.
  • You make extensive use of the #REST API in all your puppet modules
  • You use the #Atlassian #Puppet module for Nexus for creating repository, groups, assigning repository to groups, updating the main config settings, things like proxy, email, realms, and so on. The Puppet module is simply a wrapper over the Nexus REST API and allows to essentially import those abstractions into #Puppet Config Management

Here is one possible workaround that does not use any REST API

mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.1:copy
    -Dartifact=log4j:log4j:1.2.17:jar
    -DoutputDirectory=./

which is equivalent to Gist Link

war plugin vs assembly plugin

When in #apache #maven you have multiple dependencies with the same artifact id but different group id


<dependencies>
    <dependency>
        <artifactId>any</artifactId>
        <groupId>groupId1</groupId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <artifactId>any</artifactId>
        <groupId>groupId2</groupId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <artifactId>any</artifactId>
        <groupId>groupId3</groupId>
        <version>1.3</version>
    </dependency>
</dependencies>

So it’ll look like this in WEB-INF/lib

-rw------- 1 user grp  135851 Aug 24 12:21 grp1-any-1.1.jar
-rw------- 1 user grp 1406696 Sep 18 11:51 grp2-any-1.2.jar
-rw------- 1 user grp   88873 Aug 19 13:58 grp3-any-1.3.jar

Apache maven war plugin is able to detect this case and will automatically add the groupId to resolve filename conflicts. If it would not do that the last one name any.jar would win

In maven Assembly this will not occur, and the last file name will be the only one available. There is at least two way to solve this issue:

  1. Use unique groupid and artifactid name: something you can do across your module code, it can be done if these dependencies are real 3rd party librairies
  2. Use the outputFileNameMapping in assembly
<outputFileNameMapping>${artifact.groupId}-${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping> 
${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}

Another use case for outputFileNameMapping is when you want to remove the timestamp from filename but keep the version in assembly dependencySet

© 1997 - 2025 Cédric Walter blog

🌱 Powered by Hugo with theme Dream.

Others

If you like my work or find it helpful, please consider buying me a cup of coffee ☕️. It inspires me to create and maintain more projects in the future. 🦾

It is better to attach some information or leave a message so that I can record the donation 📝 , thank you very much 🙏.

Copyright information

All editorial content and graphics on our sites are protected by U.S. copyright, international treaties, and other applicable copyright laws and may not be copied without the express permission of Cedric Walter, which reserves all rights. Reuse of any of Cedric Walter editorial content and graphics for any purpose without The author ’s permission is strictly prohibited.

DO NOT copy or adapt the HTML or other code that this site creates to generate pages. It also is covered by copyright.

Reproduction without explicit permission is prohibited. All Rights Reserved. All photos remain copyright © their rightful owners. No copyright infringement is intended.

Disclaimer: The editor(s) reserve the right to edit any comments that are found to be abusive, offensive, contain profanity, serves as spam, is largely self-promotional, or displaying attempts to harbour irrelevant text links for any purpose.

About me

Cédric Walter is a French-Swiss software engineer based in Zurich, Switzerland. PGP: DF52 ADDA C81A 08A6