maven-checkstyle-plugin 不适用于 macOS 上的 google_checks.xml
maven-checkstyle-plugin not working with google_checks.xml on macOS
我有一个 Java / Maven 项目,我在家里用 Windows 构建并正确执行了 checkstyle。它使用的是内置规则集,但我也尝试了一个外部文件。
检查相同的代码/pom.xml它似乎不适用于 macOS。奇怪的是,如果我使用 sun_checks.xml
它工作正常。使用 8.8 没有任何区别。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.7</version>
</dependency>
</dependencies>
<configuration>
<encoding>UTF-8</encoding>
<configLocation>google_checks.xml</configLocation>
</configuration>
</plugin>
如果我运行那样,它会直接完成而不做任何检查:
mvn checkstyle:check -X
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T18:58:13+11:00)
Maven home: /gdev/apache-maven
Java version: 1.8.0_161, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre
Default locale: en_AU, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.3", arch: "x86_64", family: "mac"
[..]
[DEBUG] The resource 'google_checks.xml' was found as jar:file:/Users/udoheld/.m2/repository/com/puppycrawl/tools/checkstyle/8.7/checkstyle-8.7.jar!/google_checks.xml.
[DEBUG] headerLocation LICENSE.txt
[DEBUG] JarResourceLoader : trying to load "jar:file:/Users/udoheld/.m2/repository/com/puppycrawl/tools/checkstyle/8.7/checkstyle-8.7.jar"
[..]
[DEBUG] Unable to process header location: LICENSE.txt
[DEBUG] Checkstyle will throw exception if ${checkstyle.header.file} is used
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
如果我运行跟太阳一样检查:
[..]
[DEBUG] The resource 'sun_checks.xml' was found as jar:file:/Users/udoheld/.m2/repository/com/puppycrawl/tools/checkstyle/8.7/checkstyle-8.7.jar!/sun_checks.xml.
[DEBUG] headerLocation LICENSE.txt
[DEBUG] JarResourceLoader : trying to load "jar:file:/Users/udoheld/.m2/repository/com/puppycrawl/tools/checkstyle/8.7/checkstyle-8.7.jar"
[..]
[DEBUG] Checkstyle will throw exception if ${checkstyle.header.file} is used
[INFO] There are 7 errors reported by Checkstyle 8.7 with sun_checks.xml ruleset.
[ERROR] src/main/java/com/udoheld/Test.java:[0] (javadoc) JavadocPackage: Missing package-info.java file.
在不使用 maven 的情况下在命令行上尝试 checkstyle 似乎也可以工作 java -jar ~/Downloads/checkstyle-8.8/checkstyle-8.8-all.jar -c ../checkstyle-google.xml *
:
Starting audit...
[WARN] /gdev/git/test/src/main/java/com/udoheld/Test.java:18: Comment has incorrect indentation level 4, expected is 6, indentation should be the same level as line 19. [CommentsIndentation]
如日志所示,我在 macOS 10.13.3 上使用 Maven 3.5.2 Java 1.8.0_161 64 位
如何让 maven-checkstyle-plugin 在 macOS 上使用 google 规则集?
它确实 运行 它但不打印结果。如下更改插件的配置。(启用控制台输出)
<configuration>
<!-- <violationSeverity>warning</violationSeverity> -->
<consoleOutput>true</consoleOutput>
<encoding>UTF-8</encoding>
<configLocation>google_checks.xml</configLocation>
</configuration>
如果您想在检查样式发现警告时使构建失败,请取消注释 violationSeverity 行。但它不打印发现的错误总数,只打印它发现的每个错误。
我有一个 Java / Maven 项目,我在家里用 Windows 构建并正确执行了 checkstyle。它使用的是内置规则集,但我也尝试了一个外部文件。
检查相同的代码/pom.xml它似乎不适用于 macOS。奇怪的是,如果我使用 sun_checks.xml
它工作正常。使用 8.8 没有任何区别。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.7</version>
</dependency>
</dependencies>
<configuration>
<encoding>UTF-8</encoding>
<configLocation>google_checks.xml</configLocation>
</configuration>
</plugin>
如果我运行那样,它会直接完成而不做任何检查:
mvn checkstyle:check -X
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T18:58:13+11:00)
Maven home: /gdev/apache-maven
Java version: 1.8.0_161, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre
Default locale: en_AU, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.3", arch: "x86_64", family: "mac"
[..]
[DEBUG] The resource 'google_checks.xml' was found as jar:file:/Users/udoheld/.m2/repository/com/puppycrawl/tools/checkstyle/8.7/checkstyle-8.7.jar!/google_checks.xml.
[DEBUG] headerLocation LICENSE.txt
[DEBUG] JarResourceLoader : trying to load "jar:file:/Users/udoheld/.m2/repository/com/puppycrawl/tools/checkstyle/8.7/checkstyle-8.7.jar"
[..]
[DEBUG] Unable to process header location: LICENSE.txt
[DEBUG] Checkstyle will throw exception if ${checkstyle.header.file} is used
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
如果我运行跟太阳一样检查:
[..]
[DEBUG] The resource 'sun_checks.xml' was found as jar:file:/Users/udoheld/.m2/repository/com/puppycrawl/tools/checkstyle/8.7/checkstyle-8.7.jar!/sun_checks.xml.
[DEBUG] headerLocation LICENSE.txt
[DEBUG] JarResourceLoader : trying to load "jar:file:/Users/udoheld/.m2/repository/com/puppycrawl/tools/checkstyle/8.7/checkstyle-8.7.jar"
[..]
[DEBUG] Checkstyle will throw exception if ${checkstyle.header.file} is used
[INFO] There are 7 errors reported by Checkstyle 8.7 with sun_checks.xml ruleset.
[ERROR] src/main/java/com/udoheld/Test.java:[0] (javadoc) JavadocPackage: Missing package-info.java file.
在不使用 maven 的情况下在命令行上尝试 checkstyle 似乎也可以工作 java -jar ~/Downloads/checkstyle-8.8/checkstyle-8.8-all.jar -c ../checkstyle-google.xml *
:
Starting audit...
[WARN] /gdev/git/test/src/main/java/com/udoheld/Test.java:18: Comment has incorrect indentation level 4, expected is 6, indentation should be the same level as line 19. [CommentsIndentation]
如日志所示,我在 macOS 10.13.3 上使用 Maven 3.5.2 Java 1.8.0_161 64 位
如何让 maven-checkstyle-plugin 在 macOS 上使用 google 规则集?
它确实 运行 它但不打印结果。如下更改插件的配置。(启用控制台输出)
<configuration>
<!-- <violationSeverity>warning</violationSeverity> -->
<consoleOutput>true</consoleOutput>
<encoding>UTF-8</encoding>
<configLocation>google_checks.xml</configLocation>
</configuration>
如果您想在检查样式发现警告时使构建失败,请取消注释 violationSeverity 行。但它不打印发现的错误总数,只打印它发现的每个错误。