tags:

views:

30

answers:

1

I have already two questions out there on updating Maven project version. Now I have an issue with updating the dependency version of dependant sibling projects.

My simplified project setup is following:

root
|--parent
|--tool-core
|--tool
|--functional-tests

The parent project holds all the global properties and dependency management. The functional tests depend on the tool and the tool depends on the tool-core. The root pom.xml only aggregates (specifies whether the functional tests are included) and the parent project is the parent for all of the projects. I don't know if this is trivial but the parent is not included in the aggregation though, as it already is parent for each child project.

Now, my problem is if I change the version of tool with versions:set. The tool version is changed but any dependency to the tool is not. How should I do this? I have already tried more or less randomly other goals and I did try to read the manual.

I've tried already using the <dependencyManagement> section and using a property for the version in the parent but these do not get updated to the new version.

Any help is really appreciated.

Addition

I get a message "Ignoring reactor dependency: com.tool:tool:jar:null:1.2.3" at best. This is when I try to versions:use-latest-releases. However, versions:display-dependency-updates does show that there is an update on a "local dependency" (functional-tests depend on tool).

Update

It seems that the Maven looks up for new versions from the repositories, including the local one which seems quite obvious now that I think of it. However, this means that the tool has to be built and installed to local repo before updating the dependencies.

I'm only wondering if this is the right way to have integration tests as their own project. I was hoping that there would be a way to update the version straight away.

Update

Basically I have the following setup. The version dependency on functional-tests of the tool is defined by the parent project. I have omitted the tool-core since it can be handled as part of the tool.

root:

<groupId>com.somecompany</groupId>
<artifactId>x-reactor</artifactId>
<packaging>pom</packaging>
<version>1.0</version>

<profiles>
    <profile>
        <id>cli</id>
        <modules>
            <module>tool</module>
        </modules>
    </profile>
    <profile>
        <id>deploy</id>
        <modules>
            <module>tool</module>
            <module>functional-tests</module>
        </modules>
    </profile>
</profiles>

parent:

<groupId>com.somecompany</groupId>
<artifactId>x-parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.somecompany</groupId>
            <artifactId>tool</artifactId>
            <version>3.2.3</version>
        </dependency>
    </dependencies>
</dependencyManagement>

tool:

<parent>
    <groupId>com.somecompany</groupId>
    <artifactId>x-parent</artifactId>
    <version>1.0</version>
    <relativePath>../parent/pom.xml</relativePath>
</parent>

<groupId>com.somecompany</groupId>
<artifactId>tool</artifactId>
<packaging>jar</packaging>
<version>3.2.3</version>

functional-tests:

<parent>
    <groupId>com.somecompany</groupId>
    <artifactId>x-parent</artifactId>
    <version>1.0</version>
    <relativePath>../parent/pom.xml</relativePath>
</parent>

<groupId>functional-tests</groupId>
<artifactId>functional-tests</artifactId>
<version>0.1</version>
<packaging>pom</packaging>

<dependencies>
    <dependency>
        <groupId>com.somecompany</groupId>
        <artifactId>tool</artifactId>
    </dependency>
</dependencies>
A: 

Apparently one has to run the goal versions:use-latest-versions in the same path as where the pom.xml one needs to update is located. I solved this by moving the versions to the parent project and updating only that. I'm not too satisfied with this solution since it seems that the versions plugin does not support downgrading the version. Also, the new version is aquired from the (local) repository which means that the tool has to be built before updating the version. I think this was my problem initially.

Here's the script to solve this problem:

#!/bin/bash

if [[ $# -lt 1 ]]; then
    echo "Usage: $0 [version number]"
    exit 1
fi

function revert_version() {
    mvn -Pall versions:revert > /dev/null
    echo "ERROR: Failed updating the version"
    cat mvn_out.txt
    exit 1
}

v=$1
profile=cli
echo "Updating the version to $v..."
mvn -P$profile versions:set -DnewVersion=$v -DartifactId=tool -q
[ $? -eq 0 ] || revert_version

echo "Building the tool..."
mvn -P$profile install > /dev/null
[ $? -eq 0 ] || revert_version

echo "Updating the dependencies..."
mvn versions:use-latest-versions -Dincludes=com.somecompany:* -f parent/pom.xml -q
[ $? -eq 0 ] || revert_version
mvn -Pall versions:commit -q
[ $? -eq 0 ] || revert_version
mkko