Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding classes in Maven Checkstyle plugin reports

I have a Maven 2 project and I want to configure my Checkstyle report plugin so that only some of my classes are analysed. I have found the maven.checkstyle.excludes property, but despite passing this as a command line parameter (using -D=maven.checkstyle.excludes=...) I can't get it to work. I can't find anything on the Plugin documentation page. Ideally I want to be able to set this in the <configuration> section of my POM.

like image 451
Andrew Harmel-Law Avatar asked Mar 02 '10 11:03

Andrew Harmel-Law


People also ask

How do I skip Checkstyle?

If you want to disable checkstyle from your pom, you can add the checkstyle plugin to the pom and set the skip flag to prevent the check.

How do I check my Checkstyle violations?

It will also generate the violation report for the project which is available as a view in Eclipse. To view to violation report, go to Window -> Show View -> Other, and search for Checkstyle. Options for Violations and Violations Chart should be displayed.


1 Answers

If, like me, you arrived here searching for a way to exclude generated sources from checkstyle, do this:

<plugin>   <groupId>org.apache.maven.plugins</groupId>   <artifactId>maven-checkstyle-plugin</artifactId>   <version>2.15</version>   <configuration>     <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>   </configuration> </plugin> 

By default, the checkstyle:checkstyle goal of the checkstyle plugin uses ${project.compileSourceRoots}, which apparently includes generated source directories.

If you change it to ${project.build.sourceDirectory}, it will use only the source directory, not any generated source directories.

Note that while <sourceDirectory> is deprecated, the alternative, <sourceDirectories>, does not appear to work.

Edit: In comments, @Cyrusmith, @Ben, and @Olivier Callioux report that as of 2017, <sourceDirectories> works; I cannot confirm.

like image 138
drew Avatar answered Oct 08 '22 22:10

drew