问题
Can anyone help me in getting solution for the below error.
Below are the version of the components to configure
- SonarQube 5.1.2
- Soanr-Runner 2.4
- Java 1.7 [ I have to use 1.7 only since my code supports only 1.7]
- mavn 3.3.9
- sonar-cobertura-plugin-1.6.3
- sonar-findbugs-plugin-3.3
- 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
回答1:
Regardless of what you compile your code with, the SonarQube analysis should be run with Java 8. You simply need to use different JDK versions for the compile and analysis. Either that, or do everything with Java 8 and -target 1.7
.
回答2:
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?
回答3:
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.
回答4:
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>
回答5:
with sonar 7.8 it still gives the same error, below is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.naveen</groupId>
<artifactId>test-sonar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.sonarsource.scanner.maven/sonar-maven-plugin -->
<dependency>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
<outputDirectory>target/jacoco-ut</outputDirectory>
<excludes>
<exclude>com/philips/beans/*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<!-- <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration>
<source>1.8</source> <target>1.8</target> </configuration> </plugin> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Still has the problem with execution, and any quick fix will help.
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.naveen:test-sonar >------------------------
[INFO] Building test-sonar 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test-sonar ---
[INFO] Deleting /Volumes/Kanchan/workspaces/trainings/philps-cleancode/test-sonar/target
[INFO]
[INFO] -----------------------< com.naveen:test-sonar >------------------------
[INFO] Building test-sonar 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- sonar-maven-plugin:3.7.0.1746:sonar (default-cli) @ test-sonar ---
[INFO] User cache: /Users/naveenkumar/.sonar/cache
[INFO] SonarQube version: 7.8.0
[INFO] Default locale: "en_GB", source code encoding: "UTF-8" (analysis is platform dependent)
[WARNING] SonarQube scanners will require Java 11+ starting on next version
[INFO] Load global settings
[INFO] Load global settings (done) | time=113ms
[INFO] Server id: BF41A1F2-AW55NDEZScHVXVhYwlVv
[INFO] User cache: /Users/naveenkumar/.sonar/cache
[INFO] Load/download plugins
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=71ms
[INFO] Load/download plugins (done) | time=126ms
[INFO] Process project properties
[INFO] Execute project builders
[INFO] Execute project builders (done) | time=3ms
[INFO] Project key: com.naveen:test-sonar
[INFO] Base dir: /Volumes/Kanchan/workspaces/trainings/philps-cleancode/test-sonar
[INFO] Working dir: /Volumes/Kanchan/workspaces/trainings/philps-cleancode/test-sonar/target/sonar
[INFO] Load project settings for component key: 'com.naveen:test-sonar'
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=117ms
[INFO] Load active rules
[INFO] Load active rules (done) | time=1073ms
[WARNING] SCM provider autodetection failed. Please use "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project settings.
[INFO] Indexing files...
[INFO] Project configuration:
[INFO] 8 files indexed
[INFO] Quality profile for java: Sonar way
[INFO] Quality profile for xml: Sonar way
[INFO] ------------- Run sensors on module test-sonar
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=16ms
[INFO] Sensor JavaSquidSensor [java]
[INFO] Configured Java source version (sonar.java.source): 8
[INFO] JavaClasspath initialization
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.911 s
[INFO] Finished at: 2019-11-24T15:58:43+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project test-sonar: Please provide compiled classes of your project with sonar.java.binaries property -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
来源:https://stackoverflow.com/questions/40300653/failed-to-execute-goal-org-sonarsource-scanner-mavensonar-maven-plugin-3-2son