任何人都可以帮我解决以下错误。
以下是要配置的组件的版本
执行命令
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
答案 0 :(得分:6)
自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),因此你的错误。
答案 1 :(得分:3)
无论您使用哪些编译代码,SonarQube分析都应该用Java 8 运行。您只需要使用不同的JDK版本进行编译和分析。要么是这样,要么用Java 8和-target 1.7
做所有事情。
答案 2 :(得分:0)
在我的情况下,我有一个父母pom
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</pluginManagement>
</build>
我在我的孩子pom中的pluginManagement
内添加了我自己的版本,但这不起作用我必须将插件添加到<build><plugins>
节点而不是<build><pluginManagement><plugins>
。只有这时才使用新版本。
也许这有助于某人。
答案 3 :(得分:0)
最近,在docker中安装Sonorqube.5.12映像并将项目推送到Sonorqube。最初我们遇到了一些maven控制台错误,例如 major.minor版本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>
答案 4 :(得分:0)
使用声纳7.8仍会产生相同的错误,以下是我的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>
仍然存在执行问题,任何快速修复都将有所帮助。
[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