My application is build by Jenkins and Maven, I want to add the build number to jar file (this includes adding to the filename of the jar and also add the build number in the jar), potentially create a file that includes the version+build number in the jar, and I can also extract this info for other use, can someone help?
Asked
Active
Viewed 2,119 times
0
-
1Do you want to use the build number as part of the Maven version? Or do your refer to something else? – J Fabian Meier Dec 03 '19 at 15:29
-
@JFMeier Hi I'm following semantic versioning, but I also want to add a build number (e.g 1.0.0.10) 10 is the build number so that the whole versioning is unique everytime I build it. – wawawa Dec 03 '19 at 15:30
-
sorry to say but a build number does not mean anything...you could use a revision/sha of your version control would be much better (but I suppose you already use a tag to mark releases) ... – khmarbaise Dec 03 '19 at 15:54
-
yes, and I want to extract this version+build number for other use a well. The revision/sha you mentioned, I've never heard of them, can you explain a bit? Many thanks. – wawawa Dec 03 '19 at 15:59
1 Answers
1
Use should pass the build-number to the maven build so it will be set as part of the artifact version.
I recommend to use the version:set Maven plugin (see: https://www.mojohaus.org/versions-maven-plugin/set-mojo.html) in order to set the version name.
If you want to know what the current version of the project, use the following command, and then use the result combined with the build-number for setting the new version: mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version

yorammi
- 6,272
- 1
- 28
- 34
-
I guess I want to create a file that includes the version+build number in the jar, and I can also extract this info for other use, not sure if this plugin can help me do this. – wawawa Dec 03 '19 at 15:40
-
-
you mean the command is 'mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version'? This command seems not right? Can you let me know what is 'org.apache.maven.plugins:maven-help-plugin:2.1.1' for? Also I can only check the current version instead of adding it to the jar? – wawawa Dec 03 '19 at 15:53
-
the maven-help-plugin scans the pom.xml and return the 'version' of it, while you should provide the build-number using ${env.BUILD_NUMBER}, so that the versions:set argument will be -DnewVersion=${version}-${env.BUILD_NUMBER} – yorammi Dec 03 '19 at 20:11
-
The thing is I want the build number to be in the jar file, not only show in the console. – wawawa Dec 03 '19 at 20:52
-
Once you set the version using versions:set, the jar will get it in its name – yorammi Dec 04 '19 at 06:44