Reputation: 1384
I'm totally lost as to why not. Structure is like this:
using mvn checkstyle:check creates the reports (I have identical settings in reporting section) but build treats the plugin like it doesn't exist. If I change the checkstyle version, it doesn't download it, etc. Essentially it treats this config as invisible.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.13</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<maxAllowedViolations>2500</maxAllowedViolations>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
</configuration>
<executions>
<execution>
<id>checkstyle</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
</configuration>
</execution>
</executions>
</plugin>
.....
</plugins>
</pluginManagement>
</build>
Upvotes: 1
Views: 2323
Reputation: 4414
You can add the plugin to the pom as follows and it will execute as part of your build (mvn clean install):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<consoleOutput>true</consoleOutput>
<maxAllowedViolations>2500</maxAllowedViolations>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
See also: Checkstyle not working
And actually, for most of those configuration parameters (all but failsOnError, which does not have a "User Property") you can alternatively put them in your pom.xml as properties:
<properties>
...
<checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
<checkstyle.suppressions.location>checkstyle-suppressions.xml</checkstyle.suppressions.location>
<checkstyle.consoleOutput>true</checkstyle.consoleOutput>
<checkstyle.maxAllowedViolations>2500</checkstyle.maxAllowedViolations>
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
</properties>
That way you can remove them from the plugin configuration section for convenience, though either approach works. See https://maven.apache.org/plugins/maven-checkstyle-plugin/check-mojo.html for "User property" values, etc.
Upvotes: 2