Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Maven Versions Plugin (versions:use-latest-versions) not updating/changing -SNAPSHOT version to release (none -SNAPSHOT version)?

I am using the Version Maven Plugin plugin use-latest-versions functionality to update groupID=com.example* internal dependency versions to the latest version. This is executed as part of our CI system using Jenkins.

When developers start working on a new feature they branch the code, work on the branch and when the new feature is implemented (or partially implemented) the code is merged back to trunk (usually multiple times a week).

Branches version update:

  • Using "snapshot" profile. See below pom.xml snapshot profile configuration and Artifactory repo configuration
  • Command used to update version: mvn -P snapshot -B versions:use-latest-versions versions:update-properties -Dincludes=com.example* -DexcludeReactor=false -DallowSnapshots=true ...

Trunk version update:

  • Using "production" profile. See below pom.xml production profile configuration and Artifactory configuration
  • Command used to update version: mvn -P production -B versions:use-latest-versions versions:update-properties -Dincludes=com.example* -DexcludeReactor=false ...

Sometimes branch builds update com.example* dependency versions to "...-SNAPSHOT" version (this is normal because libs-snapshot Artifactory repo is used as the dependency repository which can have -SNAPSHOT dependency versions). These version updates are checked back to source control (svn).

When the code (including the pom.xml version update changes) are merged back from branches to trunk and the trunk build is executed, all com.example* internal dependency versions should be changed/updated to the latest release versions. But because of some reason when dependency versions have "-SNAPSHOT" in it versions:use-latest-versions is not changing/updating the version to the latest release (none -SNAPSHOT) version.


Example:

Artifactory repos have the flowing versions:

  • libs-snapshot has "com.example:myLib:1.1.10-SNAPSHOT", "com.example:myLib:1.1.11-SNAPSHOT"
  • libs-release has "com.example:myLib:1.1.9", "com.example:myLib:1.1.12"

Making myApp branches build will get dependency versions from libs-snapshot and update com.example:myLib version to 1.1.11-SNAPSHOT and check this update back to SVN

...    
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>myLib</artifactId>
        <version>1.1.11-SNAPSHOT</version>
    </dependency>
...

Merging code back to trunk including the above dependency version changes and running the trunk build (including version update) mvn -P production -B versions:use-latest-versions... does not change the com.example:myLib version to 1.1.12


Artifactory configuration:

  • Local repos: libs-snapshot-local (development repository); libs-release-local (release repository)
  • Virtual repos: libs-snapshot (includes libs-snapshot-local, libs-release-local and remote-repos); libs-release (includes libs-release-local and remote repos)

pom.xml configuration:

...
<profiles>
    <profile>
        <id>snapshot</id>
        <distributionManagement>
            <repository>
                <id>libs-snapshot-local</id>
                <name>Internal Applications Snapshot Repository</name>
                <url>http://example.com/artifactory/libs-snapshot-local</url>
            </repository>
        </distributionManagement>

        <repositories>
            <repository>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </snapshots>
                <id>libs-snapshot</id>
                <name>libs-snapshot</name>
                <url>http://example.com/artifactory/libs-snapshot</url>
                <releases>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </releases>
            </repository>
            <repository>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
                <id>libs-release</id>
                <name>libs-release</name>
                <url>http://example.com/artifactory/libs-release</url>
                <releases>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </releases>
            </repository>
        </repositories>

        <build>
            ...
        </build>
    </profile>

    <profile>
        <id>production</id>

        <distributionManagement>
            <repository>
                <id>libs-release-local</id>
                <name>Internal Applications Snapshot Repository</name>
                <!-- Artifacts are promoted to libs-release-local not deployed directly -->
                <url>http://example.com/artifactory/libs-snapshot-local</url>
            </repository>
        </distributionManagement>

        <repositories>
            <repository>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
                <id>libs-release</id>
                <name>libs-release</name>
                <url>http://example.com/artifactory/libs-release</url>
                <releases>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </releases>
            </repository>
        </repositories>

        <build>
            ...
        </build>
    </profile>

</profiles>

...

like image 828
Norbert Tamas Avatar asked Oct 30 '22 06:10

Norbert Tamas


1 Answers

You should make sure you are using the latest versions plugin (2.3). I believe 2.3 fixed some issues (that being said it is still an incredibly buggy plugin).

The other issue I have found with the version plugin is combining with other version goals or even other maven goals. Don't do that. For example your code above you are running versions:use-latest-versions versions:update-properties at the same time. Instead execute mvn once for each one of those goal. Yes this is a pain and slows down the build process but I found it far more reliable particularly if you use versions:update-parent (2.3 may have fixed these issues though).

I also think excludeReactor is generally broken. If you are running a version update on aggregate project I don't recommend it. Instead go to each submodule and run the command.

like image 59
Adam Gent Avatar answered Nov 10 '22 20:11

Adam Gent