cnu
cnu

Reputation: 477

Maven3- How to tell maven to use latest versions using verions-maven-plugin?

I am using Maven 3.2.5. I have a multi module project with parent P and sub-modules A(jar), B(war), C(EAR). I want to always use the latest version of dependency as we do nightly builds to QA environments. We could achieve this in Maven2 by using 'LATEST' in place of version number. But looks like this feature is disabled in MAVEN3. Now I am trying to make use of "use-latest-versions" goal in versions-maven-plugin.

I am trying to run this plugin on modules B and C so that module B will use latest artifact from module A and module C will use latest artifact from module B to build final EAR.

    **My parent POM** 
        <modelVersion>4.0.0</modelVersion>

        <groupId>GGGGGGG</groupId>
        <artifactId>JARJARAJR</artifactId>
        <version>19.1-SNAPSHOT</version>
        <packaging>pom</packaging>

        <name>JARJARAJR</name>

//Modules of this project
        <modules>
            <module>../../../Module A</module>
            <module>../../../Module Bs</module>
            <module>../../../Module C</module>
        </modules>

    <build>
            <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>versions-maven-plugin</artifactId>
                    <version>2.1</version>
                    <executions>
                        <execution>
                            <id>update-dependency-versions</id>
//Asking maven to run this goal in 'pre-clean' phase
                            <phase>pre-clean</phase>
                            <goals>
                                <goal>use-latest-versions</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <allowSnapshots>true</allowSnapshots>
                        <excludeReactor>false</excludeReactor>
                    </configuration>
                </plugin>
                </plugins>
            </pluginManagement>

    The command I am using to run parent POM is : **mvn -U clean install -P devb -    Dmaven.test.skip=true**

I am trying to invoke "use-latest-versions" goal in the "pre-clean" phase(I tried validate and initialize phases too).Bu after module A is built, maven tried to resolve the old version of Module B without running goal "use-latest-versions" for 'versions-maven-plugin".

In which phase should I run "use-latest-versions" goal so that maven updates the dependency version in Module B before trying to build it?

Upvotes: 6

Views: 8845

Answers (1)

cnu
cnu

Reputation: 477

This is how I achieved what I am looking for(Always take latest versions of dependencies):

I have setup a pre-step to "invoke top level maven targets" in jenkins and triggers the command:

mvn versions:use-latest-versions -DallowSnapshots=true -DexcludeReactor=false

on the parent pom This will update the dependency versions in the parent POM and all its child POM's. Thank you khmarbaise for trying to help me. I appreciate your time.

Upvotes: 5

Related Questions