Search code examples
mavenmaven-release-plugin

Why does release:prepare change versions back to SNAPSHOT?


I'm using the maven-release-plugin and I'm noticing that it appears to change the released version BACK to -SNAPSHOT at the end.

Here's the command line args that I'm passing to maven:

--batch-mode release:prepare -DupdateWorkingCopyVersions=false -Darguments="-DskipTests -Djava.awt.headless=true -Dmaven.javadoc.failOnError=false"

Everything appears to go well - and I notice a commit and a push from the plugin where all of the proper version numbers are indeed updated to NOT have the -SNAPSHOT.

[WARNING] Ignoring unrecognized line: ?? myProject/pom.xml.releaseBackup

I see a few of these warnings ^ in the log file (not sure if this is relevant, but appears to be related to the release plugin)

Finally I see that the plugin modifies the POMs again:

[INFO] Transforming 'myProject POM'...
[INFO]   Updating my-project to 6.2-SNAPSHOT

Following this the plugin makes and pushes a commit with the following:

[maven-release-plugin] rollback changes from release preparation of myProject-6.2

Why is this last bit happening?

I don't understand the lifecycle of release:prepare or release:perform. Why does all of my code appear to be built twice?

Any help appreciated. Thanks


Solution

  • As I understand it, release:prepare

    • Updates the POM files to the version that was specified
    • performs the build, which runs the tests
    • performs other validations (ie, no dependencies to SNAPSHOT artifacts)
    • Commits the changes (which should be restricted to the POM files and their versions)
    • Tags the source that was just committed
    • Updates the pom files back to the nominated SNAPSHOT version
    • Commits those changes

    Note: I'm not sure if that's the specific order. The above list is not an exhaustive list, it's just my recollection.

    At this point, the release doesn't exist. That's what release:perform does. Release:perform checks out the code against the TAG and builds the artifacts against the tagged source.

    This is why release:prepare moves it back to the snapshot version. It's simply preparing the source to have a release built against it. Developers working on that branch, once the tag is cut, can continue to commit changes without affecting release:perform. It also allows a release to be re-cut at a later date, as it is built against the tag.

    Of course, there are variations to this plugin which is documented. But, as I understand it, this is a common workflow for this.