Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven checkstyle plugin: Print warnings to console

I cant seem to figure out how to get maven-checkstyle-plugin to print warnings to the console when I run the check goal.

If I configure as:

<module name="Checker">
    <module name="TreeWalker">
        <module name="NPathComplexity">
            <property name="max" value="5" />
            <property name="severity" value="warning" />
        </module>
    </module>
</module>

...i see nothing in console and the check does not fail. If I change the severity to error, the check fails.

Any ideas? Am I missing something?

Plugin config is as follows

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.9.1</version>
                <configuration>
                    <includeTestSourceDirectory>true</includeTestSourceDirectory>
                    <logViolationsToConsole>true</logViolationsToConsole>
                    <configLocation>
                        rules.xml</configLocation>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
like image 535
smp7d Avatar asked May 07 '12 19:05

smp7d


People also ask

How do I check my Checkstyle violations?

To view to violation report, go to Window -> Show View -> Other, and search for Checkstyle. Options for Violations and Violations Chart should be displayed.

How do I create a Checkstyle report?

To generate the Checkstyle report as part of the Project Reports, add the Checkstyle Plugin in the <reporting> section of your pom. xml . Then, execute the site phase to generate the report.


2 Answers

I had a similar problem. This configuration worked for me.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.9.1</version>
    <configuration>
        <consoleOutput>true</consoleOutput>
    </configuration>
    <executions>
        <execution>
           <id>checkstyle</id>
           <goals>
               <goal>checkstyle</goal>
           </goals>
           <phase>prepare-package</phase>
        </execution>
    </executions>
</plugin>
like image 77
drew Avatar answered Sep 28 '22 04:09

drew


Adding <violationSeverity>warning</violationSeverity> to the <configuration> in the pom.xml worked for me:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <configuration>
                <logViolationsToConsole>true</logViolationsToConsole>
                <configLocation>checkstyle.xml</configLocation>
                <violationSeverity>warning</violationSeverity>
            </configuration>
            <executions>
            ...
            </executions>
            ...
        </plugin>

Also, I have this in my checkstyle.xml:

       <module name="Checker">

          <module name="SeverityMatchFilter">
              <!-- report all violations except ignore -->
              <property name="severity" value="ignore"/>
              <property name="acceptOnMatch" value="false"/>
          </module>

          ...

      </module>
like image 45
Gyuri Avatar answered Sep 28 '22 02:09

Gyuri