I using a maven module 'foo-common'. I am currently using SNAPSHOT versioning in this. I want that whenever there is any change in this module, it's version is incremented using build-number from jenkins and deploy it to a remote repository. However, problem with this is, if my current version is 1.0.40-SNAPSHOT and then if I want to increment the major version, then version will become 2.0.41-SNAPSHOT which does not make any sense. Can someone please suggest a better approach for this?
2 Answers
The idea with maven is that you use the mvn release plugin to move the version on from SNAPSHOT to release.
So if you did (assuming you had the correct pom):
mvn release:prepare release:perform
This would remove the SNAPSHOT for a released version, in your example this would be 1.0.40, then it would tag this version in source control using the tag, then it would push the finished artifact to your release repository as defined in the tag, then it would move the version on for the next SNAPSHOT, which in your case would be 1.0.41-SNAPSHOT.
If you wanted to do a major version release you should then move the version on "manually" with a mvn versions:set 1.1.0-SNAPSHOT.

- 7,565
- 2
- 21
- 24
Maven uses two notions: either you have a snapshot or a release. These names are highly misleading, I would call these correspondingly: temporary_candidate and permanent_version.
Snapshots seem to be versioned, sort of, but if you use a repository (like Nexus etc.) you will notice that snapshots were intended to only hold a few recent iterations, where older snapshots get quickly deleted. Also when downloading a snapshot it is clear that the intended use is to always use the newest one. The releases are held permanently; the releases are expected to be downloaded by version number.
A version number is not for a developer. It is a device of communication between developer and the tester and the deployment team and the end users.
It doesn't make sense for a tester to report "to replicate this bug: (1) deploy version 2.0.44-SNAPSHOT, (2) click XYZ button". The report is broken at the "2.0.44-SNAPSHOT" part, because it's NOT A TRUE VERSION number and tester SHOULD EXPECT that the code underneath "2.0.44-SNAPSHOT" have already changed and now has wholly different bugs. And it changes each time they re-deploy.
The intended use is to show SNAPSHOT to tester/user only when there is an ongoing dialog. As soon as situation clears up, you release.
Jenkins has a very useful Release Plugin. It allows to change the version number and to perform all release tasks (including, but not limited to maven release pluigin).

- 5,184
- 1
- 41
- 52
-
Currently I am using Jenkins Artifactory Plugin to push snapshots. If I use this plugin, then how would my application download the latest from Artifactory? I mean if there are foo-common-1.0.10 and 1.0.11 in artifactory, then while executing a build, my app should download latest foo-common from artifactory – humblebee Nov 13 '16 at 04:21
-
@falcon01 [How do I tell maven to use the latest version (and why people advice against it)](http://stackoverflow.com/questions/30571/how-do-i-tell-maven-to-use-the-latest-version-of-a-dependency) – kubanczyk Nov 13 '16 at 09:57