Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin: 3.2:sonar

Can anyone help me in getting solution for the below error.

Below are the version of the components to configure

  1. SonarQube 5.1.2
  2. Soanr-Runner 2.4
  3. Java 1.7 [ I have to use 1.7 only since my code supports only 1.7]
  4. mavn 3.3.9
  5. sonar-cobertura-plugin-1.6.3
  6. sonar-findbugs-plugin-3.3
  7. cobertura 2.6

Execution command

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

In Console Window I am getting error

[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 
like image 735
Mahesh G Avatar asked Oct 28 '16 08:10

Mahesh G


3 Answers

Since the 3.2, the SonarQube maven plugin requires Java 8. You have to use the 3.0.2 version for Java 7.

You have to explicitely add this statement to your pom :

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

Because if you do not do so, by default this plugin uses the LATEST version of the plugin (3.2), hence your error.

See http://docs.sonarqube.org/display/HOME/Frequently+Asked+Questions#FrequentlyAskedQuestions-ShouldIlockversionofSonarQubeMavenplugininmypom.xml?

like image 184
Zzirconium Avatar answered Nov 17 '22 06:11

Zzirconium


Regardless of what you compile your code with, the SonarQube analysis should be run with a specific Java version.
You simply need to use different JDK versions for the compilation and analysis.

  • For SonarQube 6.* compatibility], make sure the JAVA_HOME=/path/to/java8
  • For SonarQube 9.* compatibility], make sure the JAVA_HOME=/path/to/java11
like image 7
G. Ann - SonarSource Team Avatar answered Nov 17 '22 07:11

G. Ann - SonarSource Team


In my case I had a parent pom with

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

I've added my own version also within pluginManagement in my child pom but this didn't work I had to add the plugin to the <build><plugins> nodes instead of <build><pluginManagement><plugins>. Only then new newer version had been used.

Maybe this helps someone.

like image 1
Christian Avatar answered Nov 17 '22 06:11

Christian