maven checkstyle插件在构建期间不会失败,即使“failsonerror”设置为“true”`

kuuvgm7e  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(445)

我的项目执行严格的风格,所以我有 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>

当我运行构建时,我看到插件正在运行并检查样式,但是当存在checkstyle问题时,它应该会失败,因为我有 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] ------------------------------------------------------------------------
ds97pgxw

ds97pgxw1#

阅读日志:

[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的文档: violationSeverity 定义违反严重性的级别。 failOnViolation 当违规发生时触发“失败”事件。

相关问题