我使用maven-enforcer-plugin检查依赖收敛问题,典型输出如下:
[WARNING] Rule 1: org.apache.maven.plugins.enforcer.DependencyConvergence failed
with message:
Failed while enforcing releasability the error(s) are [
Dependency convergence error for junit:junit:3.8.1 paths to dependency are:
+-foo:bar:1.0-SNAPSHOT
+-ca.juliusdavies:not-yet-commons-ssl:0.3.9
+-commons-httpclient:commons-httpclient:3.0
+-junit:junit:3.8.1
and
+-foo:bar:1.0-SNAPSHOT
+-junit:junit:4.11
]
看到这条信息,通常我会通过排除传递性依赖来“解决”它,例如:
<dependency>
<groupId>ca.juliusdavies</groupId>
<artifactId>not-yet-commons-ssl</artifactId>
<version>0.3.9</version>
<exclusions>
<!-- This artifact links to another artifact which stupidly includes
junit in compile scope -->
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
我想了解这是否真正是一个修复方法,并且以这种方式排除库所涉及的风险。据我所见:
“修复”通常是安全的,前提是我选择使用更新的版本。这依赖于库作者保持向后兼容性。
通常不会影响Maven构建(因为近距离定义获胜),但是通过排除依赖项,我告诉Maven我知道这个问题,从而取悦了maven-enforcer-plugin。
我的想法是正确的吗?是否有其他处理此问题的方式?我对关注普遍情况的答案感兴趣-我意识到上面的junit
示例有点奇怪。