maven-checkstyle-plugin not working with google_checks.xml on macOS
Asked Answered
H

1

5

I have a Java / Maven project that I build at home with Windows and was executing checkstyle properly. It's using the builtin ruleset, but I tried an external file as well.

Checking out the same code / pom.xml it doesn't seem to work with macOS. The odd thing is if I use the sun_checks.xml it's working fine. Using 8.8 didn't make a difference.

<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>

If I run it like that, it will just complete without doing any checks:

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

If I run the same with the sun checks:

[..]
[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.

Trying the checkstyle on the commandline without using maven seems to work as well 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]

As the logs show I'm using Maven 3.5.2 on macOS 10.13.3 with Java 1.8.0_161 64 Bit.

How do I get the maven-checkstyle-plugin working with the google ruleset on macOS?

Handal answered 9/3, 2018 at 3:4 Comment(0)
G
8

It does actually run it but does not print the results. Change your plugin's configuration like below.(enabling console output)

     <configuration>
        <!-- <violationSeverity>warning</violationSeverity> -->
        <consoleOutput>true</consoleOutput>
        <encoding>UTF-8</encoding>
        <configLocation>google_checks.xml</configLocation>
      </configuration>

If you want to fail the build when check style finds warnings, uncomment the violationSeverity line. But it does not print total number of errors found, only prints each error it finds.

Gillenwater answered 10/3, 2018 at 15:9 Comment(1)
Thx! You rocks!Noman

© 2022 - 2024 — McMap. All rights reserved.