When working with many feature/release/bugix/hotfix branches, it is a bad idea to start changing the pom version as this will create merge conflicts using pull request. this plugin allow 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 automatically when running in your continuous integration server.
GPL-3.0 License
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 when using pull request
Read more here
This 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 automagically when running in your continuous integration server.
Example if your branch name is named feature/xxxx
<version>xxxx-SNAPSHOT</version>
(default)<version>xxxx</version>
(release = true)<version>0-xxxx-SNAPSHOT</version>
(forceNumericalVersion = true) useful for Apache Felix bundles<version>feature-xxxx-SNAPSHOT</version>
(filterOutBranchQualifier = false)Maven 2.0, 2.1, 2.2 and 3.0 do not currently support re-reading modifications of the pom.xml within one invocation of Maven.
You need to run this code in an own maven step like mvn clean
, then your build in mvn deploy
.
This is because Maven has read and cache the reactor content with the old version name,
the plugin properly change version on disk but there is no easy way to reload all projects in code.
(Pull request welcomed if you find how)
Travis do not checkout the whole git, but only the branch. This plugin can detect Travis environment and use the value provided from environment ${TRAVIS_BRANCH}
Add to the root pom
<plugins>
<plugin>
<groupId>com.cedricwalter</groupId>
<artifactId>git-branch-renamer-maven-plugin</artifactId>
<version>1.5.0</version>
<inherited>false</inherited> <!-- only run once in root module -->
<executions>
<execution>
<goals>
<goal>pom</goal>
</goals>
<phase>pre-clean</phase>
<configuration>
<!-- default values here for sake of example, all are optionnal -->
<release>false</release> <!-- you may want to add a profile where it is true or a -D when you want to release your project -->
<filterOutBranchQualifier>true</filterOutBranchQualifier>
<forceNumericalVersion>false</forceNumericalVersion>
<toUpperCase>false</toUpperCase>
<toLowerCase>false</toLowerCase>
<!-- if true this will set a system property variable, the variable set will be only valid in the current process vm (maven) -->
<setVariable>false</setVariable>
<!-- name of the system property variable -->
<versionFromGitBranch>versionFromGitBranch</versionFromGitBranch>
<!-- if true this will create a file in target/version.txt which contains new version number -->
<setFile>true</setFile>
<fileName>version.txt</fileName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<profiles>
<profile>
<id>rename-pom-version-like-branch</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.cedricwalter</groupId>
<artifactId>git-branch-renamer-maven-plugin</artifactId>
<version>1.5.0</version>
<inherited>false</inherited>
<executions>
<execution>
<goals>
<goal>pom</goal>
</goals>
<phase>post-clean</phase>
<configuration>
<release>false</release>
<forceNumericalVersion>false</forceNumericalVersion>
<toUpperCase>false</toUpperCase>
<toLowerCase>false</toLowerCase>
<filterOutBranchQualifier>true</filterOutBranchQualifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<profiles>
<profile>
<id>rename-pom-version-like-branch</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
<properties>
<releaseNow>false</releaseNow>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.cedricwalter</groupId>
<artifactId>git-branch-renamer-maven-plugin</artifactId>
<version>1.5.0</version>
<inherited>false</inherited>
<executions>
<execution>
<goals>
<goal>pom</goal>
</goals>
<phase>post-clean</phase>
<configuration>
<release>${releaseNow}</release>
<forceNumericalVersion>false</forceNumericalVersion>
<toUpperCase>false</toUpperCase>
<toLowerCase>false</toLowerCase>
<filterOutBranchQualifier>true</filterOutBranchQualifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
In the last 5 years I was doing the same in a build step (shell script) in Jetbrain Teamcity (https://www.jetbrains.com/teamcity/) or Atlassian Bamboo (https://www.atlassian.com/software/bamboo). This plugin is portable, stay in pom.
The method below is still valid!
branch=$(git rev-parse --abbrev-ref HEAD)
echo "osgi bundle do not accept non numerical version number, so use numerical OSGI qualifier for branch uniqueness"
version="0-$branch-SNAPSHOT"
echo "version is ${version}"
echo "filter out any eventual Branch prefixes"
# e.g. /bugfix /feature /release
version="$(echo $version | sed 's/bugfix\///g')"
version="$(echo $version | sed 's/feature\///g')"
version="$(echo $version | sed 's/hotfix\///g')"
version="$(echo $version | sed 's/0-release\///g')"
/opt/maven/apache-maven-3.3.9/bin/mvn versions:set -DgenerateBackupPoms=false -DnewVersion="$version"
echo 'Changed version in pom.xml files to ${version}'
exit 0 ```