aws-lambdacheckstyleaws-sampmd

AWS SAM build fails with error: Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.3.1


When I build my Spring Boot 3 app (JDK 21), I get the following error while running the AWS SAM build command:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.3.1:check (default) on project xxxxx: Unable to parse configuration of mojo org.apache.maven.plugins:maven-checkstyle-plugin:3.3.1:check: Basic element 'includes' must not contain child elements -> [Help 1]

But mvn clan package works fine as usual.

I tried commenting out the following in the pom.xml and the error is gone. But I need the PMD and checkstyle in my code.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-pmd-plugin</artifactId>
  <version>3.22.0</version>
  <configuration>
    <targetJdk>21</targetJdk>
    <encoding>UTF-8</encoding>
    <consoleOutput>true</consoleOutput>
    <failOnViolation>false</failOnViolation>
    <printFailingErrors>true</printFailingErrors>
    <linkXRef>false</linkXRef>
    <includes>
      <include>**/*.java</include>
    </includes>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>check</goal>
        <goal>cpd-check</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-checkstyle-plugin</artifactId>
  <version>3.3.1</version>
  <configuration>
    <configLocation>checkstyle.xml</configLocation>
    <encoding>UTF-8</encoding>
    <consoleOutput>true</consoleOutput>
    <failOnViolation>true</failOnViolation>
    <violationSeverity>warning</violationSeverity>
    <linkXRef>false</linkXRef>
    <includes>
      <include>**/*.java</include>
    </includes>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>check</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Solution

  • Seems like the <includes> parameter in maven-pmd-plugin is a "List<String>", while the <includes> in maven-checkstyle-plugin is a simple "String".

    That means, you need to replace for maven-checkstyle-plugin only the following lines

    <includes>
      <include>**/*.java</include>
    </includes>
    

    with

    <includes>**\/*.java</includes>
    

    Since this seems to be default value anyway, you can also just remove the complete includes parameter.

    But mvn clean package works fine as usual.

    That's because those plugin are executed only on verify by default. You can see this at the top of the documentation of the goal, e.g. for maven-pmd-plugin:check it says "Binds by default to the lifecycle phase: verify". For maven-checkstyle-plugin:check it says the same.