关于SonarQube+Checkstyle警告的小问题。
目前,在我的应用程序和pom中,我使用以下Checkstyle插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<outputFile>.out/reports/checkstyle/checkstyle-result.xml</outputFile>
<outputDirectory>target/reports/checkstyle</outputDirectory>
<outputFileFormat>xml</outputFileFormat>
</configuration>
</plugin>
这个插件正在完成它的工作,不用担心。
当我运行SonarQube时,我会收到的警告
Old version of checkstyle detected. Consider updating to >= v8.30
For more information see: https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html
我显然是去看网站的,但我仍然很难理解。
我拥有的Checkstyle插件是已知的最新版本3.1.2,在Maven central等上进行了检查
在SonarQube中,我运行的是最新版本8.9 LTS,以及最新版本的Checkstyle插件。
请问我缺少什么?我是否使用了某种错误的插件?
这是一个名为sonar-checkstyle
的SonarQube插件,需要在SonarQube服务器实例上安装或升级。当前版本为8.40
。
注:参考
- https://docs.sonarqube.org/latest/setup/install-plugin/
- https://docs.sonarqube.org/latest/instance-administration/plugin-version-matrix/
- https://github.com/checkstyle/sonar-checkstyle
- https://github.com/checkstyle/sonar-checkstyle/releases
编辑1
步骤1
首先,在<user_home>/.sonar/cache
有一个cache
目录(对我来说,在Windows 10上是C:Users<myuser>.sonarcache
(,请删除该cache
目录下的所有sub directories
,目的是让org.sonarsource.scanner.maven:sonar-maven-plugin
最新版本从我们的SonarQube服务器实例下载,并确保所有相关插件在SonarQube服务器示例升级/安装后都是新的。(不要忘记在完成升级/安装后重新启动它,以确保所有新的都重新加载(
步骤2
其次,确保我们在项目pom.xml
中没有指定org.sonarsource.scanner.maven:sonar-maven-plugin
,无论是在父级还是其他任何地方,以确保在执行过程中,它将是最新版本,与我们的SonarQube服务器实例version
相匹配。
不管怎样,正式文件(https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-maven/)还提到如何修复Maven插件的版本如下:-
如何修复Maven插件版本
建议锁定Maven插件的版本:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>
<!--Version that matched with our Sonar server instance version -->
</version>
</plugin>
</plugins>
</pluginManagement>
</build>
最新版本可在https://search.maven.org/artifact/org.codehaus.mojo/sonar-maven-plugin或https://search.maven.org/artifact/org.sonarsource.scanner.maven/sonar-maven-plugin最新的是版本3.9.0.2155
(注意:版本?.y.z
与我们的Sonar服务器实例版本匹配(
步骤3
最后但同样重要的是,如果我们的项目是multi-module projects
,那么在正式文件中会提到(https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-maven/)如下所示:-
在某些情况下,您可能希望将声纳:声纳目标作为专用步骤。确保将安装作为多模块的第一步项目
mvn干净安装
mvn声纳:声纳。。。
然后这里将有两个步骤,首先是mvn clean install
,然后是mvn sonar:sonar ...
。
编辑2
CCD_ 17还能够指定CCD_https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html具有作为的重要句子
Maven Checkstyle插件附带默认的Checkstyle版本:formaven checkstyle插件3.1.2,checkstyle 8.29默认使用。
然后maven-checkstyle-plugin
的配置如下所示:-
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>...choose your version...</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
<build>
...
</project>
最新版本可在https://search.maven.org/artifact/com.puppycrawl.tools/checkstyle最新版本为8.42
。