Java checkstyle maven插件3.0.0不推荐使用的参数sourceDirectory

Java checkstyle maven插件3.0.0不推荐使用的参数sourceDirectory,java,xml,maven,checkstyle,maven-checkstyle-plugin,Java,Xml,Maven,Checkstyle,Maven Checkstyle Plugin,尝试向项目添加checkstyle时,我遇到sourceDirectory参数不推荐错误 错误: [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

尝试向项目添加checkstyle时,我遇到
sourceDirectory
参数不推荐错误

错误:


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


[错误]无法在project my app上执行目标org.apache.maven.plugins:maven checkstyle插件:3.0.0:checkstyle(默认cli):生成checkstyle报告时出错。注意:您正在使用已从maven checkstyle插件中删除的“sourceDirectory”。请使用“SourceDirectory”并参考>>主版本升级至3.0.0版[帮助1]
org.apache.maven.lifecycle.LifecycleExecutionException:未能在project my app上执行目标org.apache.maven.plugins:maven checkstyle插件:3.0.0:checkstyle(默认cli):生成checkstyle报告时出错。
位于org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215)
位于org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
位于org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
我有一个SpringBootMaven项目,目前没有配置checkstyle。但是,当我检查了相同的有效pom时,我能够看到以下checkstyle配置


maven checkstyle插件
2.14
xml
假的
假的
假的
http://ldisonarci.wdf.sap.corp:8080/sonar/profiles/export?format=checkstyle&语言=java
/所有数据/项目/测试项目/src
UTF-8
真的
错误
现在我想将CheckStyleMaven插件3.0.0添加到项目中。因此,我在pom.xml中的插件管理中添加了CheckStyle3.0.0版,如下所示


org.apache.maven.plugins
maven checkstyle插件
3.0.0
google_checks.xml
${project.basedir}/src/
现在,新的有效pom包含以下内容


maven checkstyle插件
3.0.0
google_checks.xml
/所有数据/项目/测试项目/src/
xml
假的
假的
假的
/所有数据/项目/测试项目/src
UTF-8
真的
错误
如果您查看新生成的有效pom.xml,它有我没有配置的
sourceDirectory
。因此,当我运行
mvn checkstyle:checkstyle
时,它会失败,出现上述错误

如何去掉有效pom.xml中出现的
sourceDirectory

我试图用checkstyle创建一个新的虚拟项目,但它没有这个问题。请提供帮助。

使用
配置
部分中的
combine.self=“override”
帮助我解决了问题

这是解决办法

<?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>

org.apache.maven.plugins

这个答案帮助我找到了解决方案。

如果我使用
checkstyle-maven-plugin@2.9.1
在默认配置下,一切正常。
<?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>