在尝试向我的项目中添加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)
我有一个spring-boot maven项目,其中当前未配置checkstyle。但是当我检查相同的有效pom时,可以看到以下用于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&language=java</configLocation>
<sourceDirectory>/All-Data/proj/test_proj/src</sourceDirectory>
<encoding>UTF-8</encoding>
<failOnViolation>true</failOnViolation>
<violationSeverity>error</violationSeverity>
</configuration>
</plugin>
现在,我想将Checkstyle maven插件3.0.0添加到项目中。因此,我在pom.xml中的插件管理中添加了Checkstyle 3.0.0版,如下所示。
<?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>
现在,新的有效pom包含以下内容
<?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>
如果您查看新生成的有效pom.xml,它具有sourceDirectory
,我没有配置。因此,当我运行mvn checkstyle:checkstyle
时,它会失败,并出现上述错误。
如何摆脱有效pom.xml中出现的sourceDirectory
。
我试图用checkstyle创建一个新的虚拟项目,但是没有这个问题。请帮忙。
答案 0 :(得分:1)
在combine.self="override"
部分使用configuration
帮助我解决了这个问题。
这是解决方案。
<?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这个答案帮助我找到了解决方案。