检测到旧版本的 checkstyle。考虑更新到 >= v8.30

Pat*_*Pat 8 checkstyle maven sonarqube maven-checkstyle-plugin

关于 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>
Run Code Online (Sandbox Code Playgroud)

这个插件正在完成它的工作,不用担心。

当我运行 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
Run Code Online (Sandbox Code Playgroud)

我显然去阅读了该网站,但我仍然很难理解。

我拥有的 Checkstyle 插件是最新的已知版本,版本 3.1.2,在 Maven 中心等上进行了检查。

在 SonarQube 中,我运行的是最新版本 8.9 LTS,以及最新版本的 Checkstyle 插件。

请问我缺少什么?我是否使用了某种错误的插件?

Cha*_*suk 5

它是一个名为SonarQube 的插件sonar-checkstyle,需要在SonarQube服务器实例上安装或升级。当前版本是8.40.

注:参考

编辑1

步骤1

首先,有一个cache目录<user_home>/.sonar/cache(对于我在Windows 10上是C:\Users\<myuser>\.sonar\cache),请删除sub directoriescache目录下的所有内容,以便让org.sonarsource.scanner.maven:sonar-maven-plugin 最新版本从我们的SonarQube服务器实例下载它,并确保升级后所有相关插件都是新的/安装在SonarQube服务器实例上。(完成升级/安装后不要忘记重新启动它,以确保重新加载所有新内容)

第2步

其次,确保我们不在org.sonarsource.scanner.maven:sonar-maven-plugin项目的pom.xml父级或其他任何地方指定 ,目的是确保在执行期间,它将是与我们的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>
Run Code Online (Sandbox Code Playgroud)

最新版本可以在https://search.maven.org/artifact/org.codehaus.mojo/sonar-maven-pluginhttps://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 声纳:声纳 ...

那么这里会有2个步骤,mvn clean install首先是完成,然后是mvn sonar:sonar ...稍后。

编辑2

maven-checkstyle-plugin可以指定https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.htmlcheckstyle version中提到的,其中重要的句子为

Maven Checkstyle 插件附带一个默认的 Checkstyle 版本:对于 maven-checkstyle-plugin 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>
Run Code Online (Sandbox Code Playgroud)

最新版本可以在https://search.maven.org/artifact/com.puppycrawl.tools/checkstyle浏览,最新的是 version 8.42