12

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 
Mahesh G
  • 1,226
  • 4
  • 30
  • 57

7 Answers7

10

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?

Zzirconium
  • 431
  • 1
  • 10
  • 32
  • Still I am getting same 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 : Uns upported major.minor version 52.0 ` – Mahesh G Oct 28 '16 at 12:10
  • Yeah I have done Clean Install but let try by doing `project-->Maven-->Update Maven Project` and update you back. – Mahesh G Oct 28 '16 at 12:18
  • Yeah sorry my question was off topic, since this is a pure maven problem. Are you sure the pom you changed is the one that is used to run the maven ? I see no reason he still uses the 3.2 if you specified you want the 3.0.2 plugin. Are you sure the plugin snippet you added is active ? in a real build and not only pluginManagement, and in an active profile ? – Zzirconium Oct 28 '16 at 12:19
  • Yeah even I am wondering why this occurring but as @ G. Ann said it working by installing Java 8 Thanks for the quick answer !! I have up voted your answer. – Mahesh G Oct 28 '16 at 17:51
8

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
Ahmed Nabil
  • 17,392
  • 11
  • 61
  • 88
G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
  • Sure @G. Ann - SonarSource Team I will check this method and update back Thanks!! – Mahesh G Oct 28 '16 at 12:18
  • 2
    Thanks It worked like charm by installing Java 8 !! Now I wanted a permanent solution Where My Code should compile with 1.7 and my SonarQube should with Java 8 How can i do that -target 1.7 can you please help me with this. – Mahesh G Oct 28 '16 at 17:48
  • Will this work with Java 17 as well? Getting issue for java 17: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar: java.lang.ExceptionInInitializerError: null – Ragas Aug 16 '23 at 13:15
1

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.

Christian
  • 1,664
  • 1
  • 23
  • 43
0

Recently, install Sonorqube.5.12 image in docker and push the project into Sonorqube. Initially we were facing some maven console errors like major.minor version 52.0.

Later, has been fixed by below step's for me.

Add this plugs in 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>

Next, Add default DB setup in ~/.m2/settings.xml file

 <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>
Ajay Kumar
  • 4,864
  • 1
  • 41
  • 44
0

It worked for me after using Maven->update project , mvn clean install, mvn clean compile

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Kavitha T
  • 1
  • 1
0

I tried the below and it's working by my side.

        <plugin>
            <groupId>org.sonarsource.scanner.maven</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>3.8.0.2131</version>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.5</version>
            <executions>
                <execution>
                    <id>prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>3.0.2</version>
        </plugin>

Then

mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install  

Then

mvn sonar:sonar
Abd Abughazaleh
  • 4,615
  • 3
  • 44
  • 53
0

For me, I had to manually go into sonarcloud and choose Analyze New Project

mr nooby noob
  • 1,860
  • 5
  • 33
  • 56