![](/img/trans.png)
[英]How to fail a maven build, if JUnit coverage falls below certain threshold
[英]How can a maven build fail when certain dependencies are present?
在我的一個 POM 中,一個依賴項有一個錯誤的 scope。 在運行應用程序時,這個(測試)依賴是 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>
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>
您可以自定義 maven-enforcer 以包含您自己的規則,該規則實現您的特定用例(文本模式匹配)。 例如看看這里。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.