0

I am currently trying to update the dependencies for the internal libraries via the versions plugin from maven. The plugin neatly updates external libraries, but does no change on the mulitmodule libraries.

To describe what I did before

I build them before so the files are there with new versions.

On every submodule I used versions:set to set a new version (i looped through the different submodules since the major and minor versions can be different for each lib in the parent project) and built them successfully linked against the old version.

Now I want to use the versions plugin to set the new version in all dependencies and then rebuild.

when I execute:

mvn -X versions:use-latest-snapshots -DexcludeReactor=false -DallowSnapshots=true -DallowMajorUpdates=true -DallowMinorUpdates=true

he sets the versions correctly for all external libs, but not the internal ones from the reactor list. I added some debug output to show that the variables are neatly used in the command. I shortened the output of the reactorProjects but all the projects are listed properly afaik. Also in the log when I have dependencies for

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.19.4</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.19.4</version>
    </dependency>
    <dependency>
        <groupId>nl.blablub</groupId>
        <artifactId>dao</artifactId>
        <version>2.0.0-SNAPSHOT</version>
    </dependency>

for example. I see he searches for the jersey parts but not the internal one.

[DEBUG]   (f) allowIncrementalUpdates = true
[DEBUG]   (f) allowMajorUpdates = true
[DEBUG]   (f) allowMinorUpdates = true
[DEBUG]   (f) allowSnapshots = true
[DEBUG]   (f) excludeReactor = false
[DEBUG]   (f) generateBackupPoms = true
[DEBUG]   (f) localRepository =       id: local
      url: file:///home/xtroce/.m2/repository/
   layout: default
snapshots: [enabled => true, update => always]
releases: [enabled => true, update => always]

[DEBUG]   (f) processDependencies = true
[DEBUG]   (f) processDependencyManagement = true
[DEBUG]   (f) processParent = false
[DEBUG]   (s) project = MavenProject: nl.blablub:libs-mvn:0.0.1-SNAPSHOT @ /home/xtroce/development/blablub-java-repo/libs-mvn/pom.xml
[DEBUG]   (f) reactorProjects = [MavenProject: nl.blablub:libs-mvn:0.0.1-SNAPSHOT @ /home/xtroce/development/blablub-java-repo/libs-mvn/pom.xml, MavenProject: nl.blablub:base-rest-api:2.0.4-SNAPSHOT @ /home/xtroce/development/blablub-java-repo/libs-mvn/base-rest-api/trunk/pom.xml, ... ]
[DEBUG]   (f) remoteArtifactRepositories = [      id: public ...

EDIT to give an example project:

the structure will be: test - subtest-a - subtest-b

the poms are:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>subtesta</module>
        <module>subtestb</module>
    </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.5</version>
            </plugin>
        </plugins>

    </build>
    <repositories>

        <repository>
            <id>public</id>
            <name>External Dependencies</name>
            <url>http://localhost:8081/repository/maven-public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <!-- pull from Release Repository -->
        <repository>
            <id>minc-releases</id>
            <name>Release Directory</name>
            <url>http://localhost:8081/repository/maven-releases</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <!-- pull from Snapshot Repository -->
        <repository>
            <id>minc-snapshots</id>
            <name>Snapshot Repository</name>
            <url>http://localhost:8081/repository/maven-snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

pom of subtest-a:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>test</artifactId>
        <groupId>test</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>subtest-a</artifactId>
    <version>1.0-SNAPSHOT</version>

</project>

pom of subtest-b:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>test</artifactId>
        <groupId>test</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>subtest-b</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.19</version>
    </dependency>
    <dependency>
        <groupId>test</groupId>
        <artifactId>subtest-a</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    </dependencies>
</project>

steps: i do mvn clean install

it builds fine, next: increase version number of subtest-a to 1.1-SNAPSHOT

next: mvn install

I now can see the 1.1-SNAPSHOT in my ~/.m2/repository

next I run the command given

mvn -X versions:use-latest-snapshots -DexcludeReactor=false -DallowSnapshots=true -DallowMajorUpdates=true -DallowMinorUpdates=true

he does not increase the version number even though the higher version shows up in the reactor packages and the correct variables for not ignoring the reactor stuff is given to maven. in the debug i see that he does not even try to get the version number of the subtest-a project.

if i run the same command with use-latest-release he increases the version number of jersey from 1.19 to 1.19.4 so the plugin works for external dependencies, but not dependencies that are given via the reactor.

There is an error releasing the lockFile for the local repo however which could have something to do with this, but I doubt it since I don't even see the subtest-a dependency in the subtest-b projects dependency checklist.

I put the log with debug output on pastebin

https://pastebin.com/NNaSu5DJ

EDIT 2

When updating all versions to the non SNAPSHOT version and testing with goal "use-latest-release" and the same commandline options everything works as expected. The version of subtest-b is updated if subtest-a changes the version. So it seems to be some bug with the use latest snapshot part.

Xtroce
  • 1,552
  • 1
  • 17
  • 39
  • Do you have an example project for that ? – khmarbaise Mar 23 '18 at 17:02
  • @khmarbaise i added the poms of a testproject that reproduces the error for me. I also added the log output of the test project to pastebin – Xtroce Mar 24 '18 at 10:43
  • please check this link https://stackoverflow.com/questions/30571/how-do-i-tell-maven-to-use-the-latest-version-of-a-dependency – Deepa Apr 15 '19 at 07:10

1 Answers1

1

The problem is that I was not able to read the documentation correctly. it states

versions:use-latest-snapshots searches the pom for all non-SNAPSHOT versions which have been a newer -SNAPSHOT version and replaces them with the latest -SNAPSHOT version.

The problem is that I tried to update SNAPSHOT versions, while the documentation states that this is not possible. When using "use-latest-versions" I can do exactly what I want.

versions:use-latest-versions searches the pom for all versions which have been a newer version and replaces them with the latest version. 
Xtroce
  • 1,552
  • 1
  • 17
  • 39