[英]How can a maven build fail when certain dependencies are present?
In one of my POM's a dependency had a wrong scope.在我的一个 POM 中,一个依赖项有一个错误的 scope。 While running the application, this (test) dependency was the cause of an OutOfMemoryError.
在运行应用程序时,这个(测试)依赖是 OutOfMemoryError 的原因。
I would like to prevent this by adding a plugin that iterates over all (including transitive) dependencies and verify the occurrence of a certain pattern, like an artifactId containing "test".我想通过添加一个迭代所有(包括传递)依赖项并验证特定模式的出现的插件来防止这种情况,例如包含“test”的 artifactId。
How can I filter all dependencies and fail the build when a certain pattern appears?当出现某种模式时,如何过滤所有依赖项并使构建失败?
After dan1st answer, this solution fits my current needs:在 dan1st 回答之后,这个解决方案符合我目前的需求:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>*:*-test</exclude>
<exclude>*:test-*</exclude>
</excludes>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
The maven enforcer plugin allows to ban dependencies : maven 强制插件允许禁止依赖:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<searchTransitive>true</searchTransitive>
<message>Dependency not allowed!</message>
<excludes>
<!-- do one of the following: -->
<exclude>all.dependencies.with.this.group.id.are.banned</exclude>
<exclude>group.id-to-ban:artifact-id-of-artifact-to-ban</exclude>
<exclude>group.id-to-ban:artifact-id-of-artifact-to-ban:versiontoban</exclude>
<!-- wildcards with '*' are also allowed -->
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.