1

I am facing sourceDirectory parameter deprecated error while trying to add checkstyle to my project.

Error:


[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:checkstyle (default-cli) on project my-app: An error has occurred in Checkstyle report generation.: You are using 'sourceDirectory' which has been removed from the maven-checkstyle-plugin. Please use 'sourceDirectories' and refer to the >>Major Version Upgrade to version 3.0.0<< on the plugin site. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:checkstyle (default-cli) on project my-app: An error has occurred in Checkstyle report generation.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)

I am having a spring-boot maven project where checkstyle is not configured currently. But when I checked the effective pom for the same, I am able to see the following config for checkstyle.


<?xml version="1.0" encoding="UTF-8"?>
<plugin>
   <artifactId>maven-checkstyle-plugin</artifactId>
   <version>2.14</version>
   <configuration>
      <outputFileFormat>xml</outputFileFormat>
      <consoleOutput>false</consoleOutput>
      <enableRSS>false</enableRSS>
      <linkXRef>false</linkXRef>
      <configLocation>http://ldisonarci.wdf.sap.corp:8080/sonar/profiles/export?format=checkstyle&amp;language=java</configLocation>
      <sourceDirectory>/All-Data/proj/test_proj/src</sourceDirectory>
      <encoding>UTF-8</encoding>
      <failOnViolation>true</failOnViolation>
      <violationSeverity>error</violationSeverity>
   </configuration>
</plugin>

Now I want to add Checkstyle maven plugin 3.0.0 to the project. So I added checkstyle version 3.0.0 to plugin management in the pom.xml like below.

<?xml version="1.0" encoding="UTF-8"?>
<plugins>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
      <version>3.0.0</version>
      <configuration>
         <configLocation>google_checks.xml</configLocation>
         <sourceDirectories>
            <sourceDirectory>${project.basedir}/src/</sourceDirectory>
         </sourceDirectories>
      </configuration>
   </plugin>
</plugins>

Now the new effective pom contains the following


<?xml version="1.0" encoding="UTF-8"?>
<plugin>
   <artifactId>maven-checkstyle-plugin</artifactId>
   <version>3.0.0</version>
   <configuration>
      <configLocation>google_checks.xml</configLocation>
      <sourceDirectories>
         <sourceDirectory>/All-Data/proj/test_proj/src/</sourceDirectory>
      </sourceDirectories>
      <outputFileFormat>xml</outputFileFormat>
      <consoleOutput>false</consoleOutput>
      <enableRSS>false</enableRSS>
      <linkXRef>false</linkXRef>
      <sourceDirectory>/All-Data/proj/test_proj/src</sourceDirectory>
      <encoding>UTF-8</encoding>
      <failOnViolation>true</failOnViolation>
      <violationSeverity>error</violationSeverity>
   </configuration>
</plugin>

If you look at the newly generated effective pom.xml, it has sourceDirectory which I didn't configure. Hence when I run mvn checkstyle:checkstyle it fails with above error mentioned above.

How do I get rid of the sourceDirectory which appears in effective pom.xml.

I tried to create a new dummy project with checkstyle but it doesn't have this problem. Please help.

Sivasankar
  • 753
  • 8
  • 22

1 Answers1

2

Using combine.self="override" in configuration section helped me solve the issue.

Here is the solution.

<?xml version="1.0" encoding="UTF-8"?>
<build>
   <pluginManagement>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.7.1</version>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>3.0.0</version>
         </plugin>
         <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.18</version>
               </dependency>
            </dependencies>
            <configuration combine.self="override">
               <configLocation>config/checkstyle_google.xml</configLocation>
               <sourceDirectories>
                  <sourceDirectory>${project.basedir}/src/</sourceDirectory>
               </sourceDirectories>
            </configuration>
         </plugin>
      </plugins>
   </pluginManagement>
</build>

https://stackoverflow.com/a/8119747/4286434 This answer helped me to find the solution.

Sivasankar
  • 753
  • 8
  • 22