简体   繁体   English

在带有插件的Maven中从Nexus选取最新版本(不是快照版本)

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

I am using Maven 3.5 . 我正在使用Maven 3.5 I have a multimodule project structure: Module A is parent and has two children Module B and Module C. 我有一个多模块项目结构:模块A是父级,有两个子级模块B和模块C。

My requirement is: I would like to have latest release from Nexus for certain third party jars. 我的要求是:对于某些第三方jar,我希望获得Nexus的最新版本。 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. 我读到在pom.xml中指定RELEASE不适用于maven 3.x版本。 But I tried it and it is working fine. 但是我尝试了一下,效果很好。 (using IntelliJ just for info) 1) So why is it working for me ? (仅将IntelliJ用作信息) 1)为什么它对我有用?

2) Should I be using RELEASE with Maven 3.5 ? 2)我应该在Maven 3.5中使用RELEASE吗?

I also read that one can use Maven "versions-maven-plugin" with goal "use-latest-releases" with Maven 3.x. 我还读到可以在Maven 3.x中将Maven“ versions-maven-plugin”与目标“ use-latest-releases”一起使用。 I am not sure how to use it exactly. 我不确定如何正确使用它。 I have tried following: 我尝试了以下方法:

in my parent pom.xml from Module A: 在我来自模块A的父pom.xml中:

<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 ? 现在3)我应该如何在子模块中的依赖项的版本标签中指定什么? 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. 基本上,我想知道一个人如何可以实际使用这个特定的Maven插件并实现目标。 I read Maven documentation for it but could not apply it. 我阅读了Maven文档,但无法应用。

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). 1)由于尚未禁用RELEASE版本功能,因此它仍在工作(即使这是“不好的做法”,因为它违反了可复制的构建原理)。 People answering in this other quesiton also report that RELEASE still works: 在另一个问题中回答的人们还报告说,RELEASE仍然有效:

How do I tell Maven to use the latest version of a dependency? 如何告诉Maven使用最新版本的依赖项?

2) It's really up to you if you use RELEASE or not. 2)是否使用RELEASE取决于您。 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. 想象一下,测试团队更改了他们的api并释放了他们的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. 您必须权衡使用RELEASE的便利性。 Plus continually pinging your artifactory server for latest versions (if there are many) will slow down your build. 再加上不断对您的工件服务器执行ping操作以获得最新版本(如果有很多版本),将会减慢您的构建速度。

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). 3)如果您要使用确切的版本号(而不是RELEASE),我个人认为这是最好的方法,则应在模块A(而不是模块C)中定义它们,甚至在模块A的父pom中定义(即我们如何在工作场所做到这一点)。 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 根据要求,以下是使用maven插件的方法: mvn versions:use-latest-releases ,可能还会跟着mvn versions:commit

Have a read of the documentation, in particular the "usage" page: 阅读文档,特别是“用法”页面:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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