Maven自动SNAPSHOT更新 [英] Maven automatic SNAPSHOT update

查看:1056
本文介绍了Maven自动SNAPSHOT更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个具有以下POM的项目:

Let's say I have one project with the following POM:

<groupId>com.mine</groupId>
<artifactId>coreJar</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>

然后在另一个项目中,我总是要引用最新的SNAPSHOT:

And then in another project I always want to reference the latest SNAPSHOT:

<dependencies> 
    <dependency>
        <groupId>com.mine</groupId>
        <artifactId>coreJar</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    ...
<dependencies> 

但是我希望它不总是0.0.1-SNAPSHOT,而是要始终获取最新的SNAPSHOT版本.过去,您可以使用LATEST,但是自从合理的原因起,此功能已被弃用.

But instead of 0.0.1-SNAPSHOT, I want it to always grab the latest SNAPSHOT version. In the past you could use LATEST, but this has since been deprecated (for reasonable reasons).

我确实了解您可以指定版本,例如:

[1.5,)

但是我无法使其与"-SNAPSHOT"一起使用:

But I could never get it to work with a "-SNAPSHOT":

[0.0.1,)-SNAPSHOT // Doesn't work!

然后的问题是,如何让Maven在我的其他项目中获取最新的SNAPSHOT?

The question then is how do I get maven to grab the latest SNAPSHOT in my other project?

推荐答案

关于依赖范围和SNAPSHOT依赖的几句话(引用依赖中介和冲突解决方法设计文档):

A few words about dependency ranges and SNAPSHOT dependencies (quoting the Dependency Mediation and Conflict Resolution design document):

将SNAPSHOT版本纳入规范

依赖项范围的解析不应解析为快照(开发版本),除非将其作为显式边界包括在内.除非您显式使用新功能,否则无需针对开发代码进行编译,在该功能下,快照将成为版本规范的下限.由于发行版被认为比其所属的快照新,因此将在较旧的快照中对其进行选择.

Incorporating SNAPSHOT versions into the specification

Resolution of dependency ranges should not resolve to a snapshot (development version) unless it is included as an explicit boundary. There is no need to compile against development code unless you are explicitly using a new feature, under which the snapshot will become the lower bound of your version specification. As releases are considered newer than the snapshot they belong to, they will be chosen over an old snapshot if found.

因此,要回答您的问题,使用具有依赖性范围的SNAPSHOT的唯一方法是作为边界,并且您不会通过设计自动获得更高的SNAPSHOT版本(确实是有意义的).

So, to answer your question, the only way to use a SNAPSHOT with dependency ranges is as boundary and you won't get higher SNAPSHOT versions automatically by design (which really makes sense).

个人而言,我不喜欢使用依赖范围,因为我发现它可能导致构建可再现性问题并使构建更加脆弱.我不推荐他们.

Personally, I don't like to use dependency ranges because I find that it can lead to build reproducibility issues and makes the build more fragile. I do not recommend them.

以防万一,升级SNAPSHOT版本通常意味着您要发布一些代码,而maven版本插件对此提供了支持(请参见

Just in case, upgrading the SNAPSHOT version typically means that you are releasing some code and the maven release plugin provides support for that (see the Updating POM Versions).

这篇关于Maven自动SNAPSHOT更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆