【发布时间】:2021-06-03 07:24:14
【问题描述】:
在我的一个 POM 中,依赖项的范围有误。 在运行应用程序时,这个(测试)依赖是 OutOfMemoryError 的原因。
我想通过添加一个迭代所有(包括传递)依赖项并验证特定模式的出现的插件来防止这种情况,例如包含“test”的 artifactId。
当出现某种模式时,如何过滤所有依赖项并导致构建失败?
在 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>
【问题讨论】:
-
你应该小心做这样的事情。这听起来合乎逻辑,但祝你在构建一个依赖于 artifact-id "attest-verifier" 库的项目时好运
-
公平点,当它发生时必须处理这个问题