AWS SAM 构建失败并出现错误:无法执行目标 org.apache.maven.plugins:maven-checkstyle-plugin:3.3.1

问题描述 投票:0回答:1

当我构建 Spring Boot 3 应用程序 (JDK 21) 时, 我在运行 AWS SAM 构建命令时收到以下错误:

[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]

但是

mvn clan package
照常工作正常。

我尝试在 pom.xml 中注释掉以下内容,错误消失了。但我的代码中需要 PMD 和 checkstyle。

<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>
aws-lambda checkstyle aws-sam pmd
1个回答
0
投票

看起来maven-pmd-plugin中的

<includes>
参数是一个“List”,而maven-checkstyle-plugin中的
<includes>
是一个简单的“String”。

这意味着,您只需替换 maven-checkstyle-plugin 以下几行

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

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

由于这似乎是默认值,您也可以删除完整的包含参数。

但是

mvn clean package
照常工作正常。

那是因为这些插件默认仅在验证时执行。您可以在目标文档的顶部看到这一点,例如对于 maven-pmd-plugin:check 它表示“默认绑定到生命周期阶段:验证”。对于 maven-checkstyle-plugin:check 它说的是一样的。

© www.soinside.com 2019 - 2024. All rights reserved.