CodeHeaven
CodeHeaven

Reputation: 315

Exclude *target* directory from the maven-checkstyle-plugin scan

I am using Apache Maven Checkstyle plugin in my pom.xml. I am trying to exclude the target directory from the check style scan but no luck so far. Here is the pom code i am trying.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <executions>
                <execution>
                    <id>checkstyle-check</id>
                    <phase>test</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <configLocation>checkstyles.xml</configLocation>
                <failsOnError>true</failsOnError>
                <failOnViolation>true</failOnViolation>
                <consoleOutput>true</consoleOutput>
                <includes>**\/*.java,**\/*.groovy</includes>
                <excludes>**WHAT GOES HERE TO EXCLUDE THE TARGET DIRECTORY**</excludes>
            </configuration>
        </plugin>

Upvotes: 2

Views: 6807

Answers (2)

Boris
Boris

Reputation: 24443

In Apache Maven Checkstyle Plugin version 3 to specify the location of the source directories we have to use sourceDirectories parameter. Then we can specify only directories of application/library and test sources to be used for Checkstyle:

<sourceDirectories>
  <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
  <sourceDirectory>${project.build.testSourceDirectory}</sourceDirectory>
</sourceDirectories>

Now only src/main/java and src/test/java will be analysed.

Here is my full working example:

<!-- Apache Maven Checkstyle Plugin (checks Java code adheres to a coding standard) -->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-checkstyle-plugin</artifactId>
  <version>${maven-checkstyle-plugin.version}</version>
  <executions>
    <execution>
      <phase>test</phase>
      <goals>
        <goal>check</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <sourceDirectories>
      <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
      <sourceDirectory>${project.build.testSourceDirectory}</sourceDirectory>
    </sourceDirectories>
    <!-- relates to https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml -->
    <configLocation>/src/main/resources/checkstyle.xml</configLocation>
  </configuration>
</plugin>

Upvotes: 5

Guilherme Mussi
Guilherme Mussi

Reputation: 1057

<excludes>**/generated/**/*</excludes>

This will remove the generated files from the plugin.

Upvotes: 1

Related Questions