简体   繁体   中英

Picking Latest Release (not snapshot version) from Nexus in Maven with Plugin

I am using Maven 3.5 . I have a multimodule project structure: Module A is parent and has two children Module B and Module C.

My requirement is: I would like to have latest release from Nexus for certain third party jars. These are basically the jars from the Test Unit. Please note I dont want to have Snapshot versions.

I read that specifying RELEASE in pom.xml in does not work with maven 3.x versions. But I tried it and it is working fine. (using IntelliJ just for info) 1) So why is it working for me ?

2) Should I be using RELEASE with Maven 3.5 ?

I also read that one can use Maven "versions-maven-plugin" with goal "use-latest-releases" with Maven 3.x. I am not sure how to use it exactly. I have tried following:

in my parent pom.xml from Module A:

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>versions-maven-plugin</artifactId>
   <version>2.5</version>
   <executions>
      <execution>
         <goals>
            <goal>use-latest-releases</goal>
         </goals>
      </execution>
   </executions>
</plugin>

Now 3) how and what should I specify in version tag of my dependency in sub module say C ? I wrote like following:

<properties>
    <!-- V dependencies -->
    <version.vvv.iii.piiii></version.vvv.iii.piiii>
</properties>

<dependency>
        <groupId>c.b.ttt</groupId>
        <artifactId>V-RApi</artifactId>
        <version>version.vvv.iii.piiii</version>      
 </dependency>

Basically I want to know how one can use this particular maven plugin and goal practically. I read Maven documentation for it but could not apply it.

1) It's still working since the RELEASE version feature hasnt been disabled yet (even though it is "bad practise" since it violates the principle of reproducible builds). People answering in this other quesiton also report that RELEASE still works:

How do I tell Maven to use the latest version of a dependency?

2) It's really up to you if you use RELEASE or not. Just be aware that not having reproducible builds is widely regarded as bad practise. Imagine that the test team changes their api and releases their jar. You rebuild your own project, which takes a new version of the test team jar, and your build fails (even though you didnt change anything). You have to weigh that up against the convenience of using RELEASE. Plus continually pinging your artifactory server for latest versions (if there are many) will slow down your build.

3) If you are going to use exact verison numbers (instead of RELEASE), which personally I regard as the best approach, then they should be defined in module A (not module C), or even a parent pom of module A (thats how we do it in my work place). Defining exact version numbers all in one place, and as far up in the module heirarchy as is practical, is a generally a good thing - it's tidy and consistent and less prone to errors and inconsistencies.

Edit:

As requested, here is how to use the maven plugin: mvn versions:use-latest-releases , possibly also followed by mvn versions:commit

Have a read of the documentation, in particular the "usage" page:

http://www.mojohaus.org/versions-maven-plugin/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM