我的 pom.xml 中有一些 Maven 配置文件。我已配置詹金斯为每个配置文件运行夜间测试。
今天我发现我的詹金斯配置中的一个配置文件名称存在拼写错误。事实证明,如果 Maven 无法归档配置文件,它将运行默认配置文件。
如果配置文件不存在,有没有办法强制 maven 抛出错误?
Maven Enforcer 插件版本 3.0.0-M2 为此引入了内置检查 requireProfileIdsExist:
当使用一个或多个未知的配置文件 ID 运行 Maven 时,Maven 会向您发出警告。 由于这个原因,这条规则实际上会破坏构建。
以下是如何设置项目来使用此规则
<project> ... <build> <plugins> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>3.0.0-M2</version> <executions> <execution> <id>enforce</id> <configuration> <rules> <requireProfileIdsExist/> </rules> </configuration> <goals> <goal>enforce</goal> </goals> </execution> </executions> </plugin> ... </plugins> </build> ... </project>
您可以使用 Maven Enforcer 插件
您可以检查配置文件是否存在,而无需在 pom.xml 中配置 Maven Enforcer 插件:
> mvn enforcer:enforce -Denforcer.rules=requireProfileIdsExist -PprofileToCheck
...
[WARNING] The requested profile "profileToCheck" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0:enforce (default-cli) on project idegen: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]