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

7

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 
Doorknob answered 28/10, 2016 at 8:2 Comment(0)
I
9

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
Impignorate answered 28/10, 2016 at 11:42 Comment(3)
Sure @G. Ann - SonarSource Team I will check this method and update back Thanks!!Doorknob
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.Doorknob
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: nullAmphisbaena
S
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?

Stymie answered 28/10, 2016 at 8:9 Comment(4)
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 Doorknob
Yeah I have done Clean Install but let try by doing project-->Maven-->Update Maven Project and update you back.Doorknob
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 ?Stymie
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.Doorknob
I
9

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
Impignorate answered 28/10, 2016 at 11:42 Comment(3)
Sure @G. Ann - SonarSource Team I will check this method and update back Thanks!!Doorknob
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.Doorknob
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: nullAmphisbaena
T
0

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.

Tussah answered 21/11, 2017 at 8:7 Comment(0)
I
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>
Irregular answered 5/6, 2018 at 12:1 Comment(0)
C
0

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

Commencement answered 29/7, 2022 at 4:33 Comment(0)
M
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
Matthaus answered 14/4, 2023 at 14:2 Comment(0)
W
-1

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

Waterless answered 24/4, 2023 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.