黑名单Maven依赖项

有没有一种方法,例如Maven插件,可以列出不需要的/黑色列出的依赖项(直接和传递),如果它检测到列出的依赖项之一,则无法构建?

在我的项目中,我们严格要求摆脱Apache Commons Logging并将其替换为SLF4J JCL Bridge。 我知道我们必须排除不需要的deps自己,但是如果有人添加了一个带来黑名单依赖的依赖项,我想让构建失败。

您可以使用maven-enforcer-plugin禁止某些依赖maven-enforcer-plugin

这是他们的例子,其中包含您排除Apache Commons Logging的更新。

  [...]    org.apache.maven.plugins maven-enforcer-plugin 1.1.1   enforce-banned-dependencies  enforce      commons-logging:commons-logging    true       [...]  

运行mvn install时的输出将是:

 [WARNING] Rule 1: org.apache.maven.plugins.enforcer.BannedDependencies failed with message: Found Banned Dependency: commons-logging:commons-logging:jar:1.1.1 Use 'mvn dependency:tree' to locate the source of the banned dependencies. 

这一切都以BUILD FAILURE结束。

是的, enforcer插件通过其bannedDependencies规则支持此function 。