Question: How do you handle feature branches for maven multi project builds?
Jenkins builds and deploys these branches to keep build overhead on develop
How about the following approach:
scmBranch
property (that is, the current git branch)master
, develop
, etc.) and populate (or not) a new Maven property, say branch.classifier
branch.classifier
property: if empty, no classifier will be applied (default behavior, applied to the develop
branch, for example); otherwise a classifier named after the current branch will be dynamically applied.Here is a minimal example:
org.codehaus.mojo
buildnumber-maven-plugin
1.4
validate
create
org.codehaus.mojo
build-helper-maven-plugin
1.10
regex-property
regex-property
branch.classifier
${scmBranch}
(^develop)|(^master)|(^release.*)
false
maven-jar-plugin
3.0.2
${branch.classifier}
The snippet below is basically populating the scmBranch
property dynamically, then setting the branch.classifier
to its value only if different than develop
, master
or release*
, then setting it as a classifier.
Main advantages of this approach:
The classifier allows to distinguish artifacts that were built from the same POM but differ in their content.
Examples
Hence, you would have the following artifacts generated:
develop
: e.g. project-1.0.0-SNAPSHOT.jar
(empty classifier, hence not applied, as handled by the regex)featureA
: e.g. project-1.0.0-SNAPSHOT-featureA.jar
hotfix-JIRA123
: e.g. project-1.0.0-hotfix-JIRA123.jar
release-sprint42
: that's up to you, I added this case to not apply the branch name, simply because in these cases I prefer to esplicitely set a special classifier, RC
, for release candidates, but that's a matter of conventions/taste/habits, you can apply the same approach on this branch as well, as long as no clashes will be created on Nexus. Also note: when using JIRA/Stash/Git integration, the release branch name is normally something like release/v0.1.0
, where the /
character may cause issues in some OS (still something fixeable via further regex replacing though, if really required).master
: hey, no one should work on master
:) the case is there just as a double check, but that's actually not requiredWarnings on this approach:
.pom
files containing branch classifier can get into conflicts with the mainline build (i.e. overriding it)