9

谁能帮我解决以下错误。

以下是要配置的组件版本

  1. SonarQube 5.1.2
  2. Soanr-Runner 2.4
  3. Java 1.7 [我只能使用 1.7,因为我的代码只支持 1.7 ]
  4. mavn 3.3.9
  5. 声纳-cobertura-plugin-1.6.3
  6. 声纳-findbugs-plugin-3.3
  7. 科贝图拉 2.6

执行命令

mvn -fn -e org.sonarsource.scanner.maven:sonar-maven-plugin:RELEASE:sonar -Dsonar.jdbc.url="jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance" -Dsonar.host.url=http://localhost:9000 -DskipTests

在控制台窗口中我收到错误

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:
3.2:sonar (default-cli) on project NWT_Core: Execution default-cli of goal org.s
onarsource.scanner.maven:sonar-maven-plugin:3.2:sonar failed: Unable to load the
 mojo 'sonar' in the plugin 'org.sonarsource.scanner.maven:sonar-maven-plugin:3.
2' due to an API incompatibility: org.codehaus.plexus.component.repository.excep
tion.ComponentLookupException: org/sonarsource/scanner/maven/SonarQubeMojo : Unsupported major.minor version 52.0 
4

4 回答 4

10

从 3.2 开始,SonarQube maven 插件需要 Java 8。Java 7 必须使用 3.0.2 版本。

您必须明确将此语句添加到您的 pom 中:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>sonar-maven-plugin</artifactId>
    <version>3.0.2</version>
</plugin>

因为如果你不这样做,默认情况下这个插件使用最新版本的插件(3.2),因此你的错误。

请参阅http://docs.sonarqube.org/display/HOME/Frequently+Asked+Questions#FrequentlyAskedQuestions-ShouldIlockversionofSonarQubeMavenplugininmypom.xml

于 2016-10-28T08:09:41.907 回答
6

无论您使用什么编译代码,SonarQube 分析都应该使用特定的 Java 版本运行。
您只需要使用不同的JDK版本进行编译分析

  • 对于SonarQube 6. * 兼容性],请确保 JAVA_HOME=/path/to/ java8
  • 对于SonarQube 9. * 兼容性],请确保 JAVA_HOME=/path/to/ java11
于 2016-10-28T11:42:22.640 回答
1

就我而言,我有一个父母 pom

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.codehaus.sonar</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <version>2.5</version>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

我也在pluginManagement我的子 pom 中添加了我自己的版本,但这不起作用我不得不将插件添加到<build><plugins>节点而不是<build><pluginManagement><plugins>. 只有这样新的更新版本才被使用。

也许这对某人有帮助。

于 2017-11-21T08:07:37.213 回答
0

最近,在docker中安装Sonorqube.5.12镜像并将项目推送到Sonorqube中。最初,我们遇到了一些 maven 控制台错误,例如major.minor version 52.0

后来,已通过以下步骤为我修复。

在 Maven 中添加这个插件。

  <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>2.6</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
        </plugin>
    </plugins>

接下来,在 ~/.m2/settings.xml 文件中添加默认数据库设置

 <profile>
    <id>sonar</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <sonar.jdbc.url>jdbc:h2:tcp://localhost:9092/sonar</sonar.jdbc.url>
            <sonar.host.url>http://localhost:9000</sonar.host.url>
            <sonar.jdbc.username>sonar</sonar.jdbc.username>
            <sonar.jdbc.password>sonar</sonar.jdbc.password>
            <sonar.pdf.username>admin</sonar.pdf.username>
            <sonar.pdf.password>admin</sonar.pdf.password>
        </properties>
    </profile>
于 2018-06-05T12:01:27.177 回答