gpt4 book ai didi

java - checkstyle-maven-plugin 3.0.0 已弃用参数 sourceDirectory

转载 作者:行者123 更新时间:2023-12-02 10:00:46 27 4
gpt4 key购买 nike

我在尝试将 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&amp;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添加到项目中。所以我将 checkstyle 版本 3.0.0 添加到 pom.xml 中的插件管理中,如下所示。

<?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 创建一个新的虚拟项目,但它没有这个问题。请帮忙。

最佳答案

configuration部分使用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>

https://stackoverflow.com/a/8119747/4286434这个答案帮助我找到了解决方案。

关于java - checkstyle-maven-plugin 3.0.0 已弃用参数 sourceDirectory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55655663/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com