gpt4 book ai didi

java - 即使 `failsOnError` 设置为 `true`,Maven Checkstyle 插件在构建期间也不会失败

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:01:14 24 4
gpt4 key购买 nike

我的项目强制执行严格的样式,因此我将 maven-checkstyle-plugin 作为构建的一部分运行。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle.version}</version> // 3.0.0
<executions>
<execution>
<id>checkstyle</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<configLocation>google_checks.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
</execution>
</executions>
</plugin>

当我运行构建时,我看到插件正在运行并检查样式,但是当出现检查样式问题时它应该会失败,因为我设置了 true 标志。

它继续运行并且构建成功的原因是什么?

[INFO] --- maven-checkstyle-plugin:3.0.0:check (checkstyle) @ demo-api ---
[INFO] Starting audit...
...
...
[WARN] /Users/jeeves/git/jeeves/demo/src/main/java/com/demo/api/routes/UserRoutes.java:9:57: Parameter name 'BASE_PATH' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'. [ParameterName]
[WARN] /Users/jeeves/git/jeeves/demo/src/main/java/com/demo/api/routes/UserRoutes.java:13: Line is longer than 100 characters (found 102). [LineLength]
Audit done.
...
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.153 s
[INFO] Finished at: 2018-08-24T09:53:57-04:00
[INFO] Final Memory: 37M/806M
[INFO] ------------------------------------------------------------------------

最佳答案

阅读日志:

[WARN] /Users/jeeves/git/jeeves/demo/src/main/java/com/demo/api/routes/UserRoutes.java:9:57: Parameter name 'BASE_PATH' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'. [ParameterName]
[WARN] /Users/jeeves/git/jeeves/demo/src/main/java/com/demo/api/routes/UserRoutes.java:13: Line is longer than 100 characters (found 102). [LineLength]
Audit done.

那些是警告而不是错误,所以 <failsOnError>true</failsOnError>不会触发。

将以下行添加到 configuration应该改变行为:

<violationSeverity>warning</violationSeverity>
<failOnViolation>true</failOnViolation> <!-- defaults as true, can be omitted -->

请参阅 maven-checkstyle-plugin-2.16 的文档:

关于java - 即使 `failsOnError` 设置为 `true`,Maven Checkstyle 插件在构建期间也不会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52006084/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com