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

微笑、不失礼 提交于 2019-12-23 09:26:04

问题


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). My maven module A has the following dependency:

<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. Is there any way to check version of the dependency in repo and fail the build if newer version is already available.

I hope that versions-maven-plugin can make it. But I can not find appropriate configuration.


回答1:


This problem can be solved with the 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.




回答2:


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
  2. then use the scm:check-local-modification or the release plugin as the release plugin IIRC checks for local modifications.

Here is an example checking for the latest parent pom:

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


来源:https://stackoverflow.com/questions/17463116/how-to-fail-maven-build-if-newer-version-of-dependency-exists-in-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!