簡體   English   中英

即使將“failsOnError”設置為“true”,Maven Checkstyle 插件在構建期間也不會失敗

[英]Maven Checkstyle Plugin doesn't fail during build even though `failsOnError` is set to `true`

我的項目強制執行嚴格的樣式,因此我將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的文檔:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM