简体   繁体   English

如果存储库中存在较新版本的依赖项,如何使maven构建失败?

[英]How to fail maven build if newer version of dependency exists in repository?

Well, the problem is that I want maven to check dependency version on build and warn me if there are any newer dependency versions (in fact - notify me if I use an outdated version of some module). 好吧,问题是我希望maven在构建时检查依赖版本,并警告我是否有任何更新的依赖版本(事实上 - 如果我使用某个模块的过时版本通知我)。 My maven module A has the following dependency: 我的maven模块A具有以下依赖关系:

<dependency>
    <groupId>com.example.mycompany</groupId>
    <artifactId>commons</artifactId>
    <version>1.0.3</version>
</dependency>

And com.example.mycompany:commons module in fact can already have 1.0.4 version. com.example.mycompany:commons模块实际上已经有1.0.4版本了。 Is there any way to check version of the dependency in repo and fail the build if newer version is already available. 有没有办法在repo中检查依赖项的版本,如果新版本已经可用,则无法构建。

I hope that versions-maven-plugin can make it. 我希望versions-maven-plugin可以实现。 But I can not find appropriate configuration. 但我找不到合适的配置。

This problem can be solved with the maven-enforcer-plugin . 使用maven-enforcer-plugin可以解决这个问题。 You have to create your own custom rule , because non of the standard rules seem to match your needs. 您必须创建自己的自定义规则 ,因为非标准规则似乎符合您的需求。

The notion of the rule you are going to implement should be enforce dependencies are up to date . 您要实施的规则的概念应该是强制执行依赖是最新的 To implement the check you could get some inspiration by the versions-maven-plugin you mention. 要实现检查,您可以通过您提到的versions-maven-plugin获得一些灵感。

If you are using source control and a continuous integration server (which is a safe assumption) you can: 如果您正在使用源代码管理和持续集成服务器(这是一个安全的假设),您可以:

  1. use the versions plugin and let it modify the pom 使用版本插件 ,让它修改pom
  2. then use the scm:check-local-modification or the release plugin as the release plugin IIRC checks for local modifications. 然后使用scm:check-local-modification或release插件作为发布插件IIRC检查本地修改。

Here is an example checking for the latest parent pom: 以下是检查最新父pom的示例:

mvn versions:update-parent scm:check-local-modification -DallowSnapshots=false -DgenerateBackupPoms=false

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

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