Java8 项目上的 SonarQube 给出了 jacoco-Exception

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23923443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 09:04:46  来源:igfitidea点击:

SonarQube on Java8-project gives jacoco-Exception

javasonarqubejacocojava-8

提问by Rop

I just downloaded the latest version, SonarQube 4.3, then try build a java-8 project with:

我刚刚下载了最新版本 SonarQube 4.3,然后尝试使用以下命令构建一个 java-8 项目:

  mvn clean install
  mvn sonar:sonar

That gives me the Exception below.

这给了我下面的例外。

Googling, I got the impression this is an earlier issue that should have been fixed... ?

谷歌搜索,我觉得这是一个应该修复的早期问题......?

http://sonarqube.15.x6.nabble.com/Sonar-analyze-Java-1-8-project-Failure-td5023663.html

http://sonarqube.15.x6.nabble.com/Sonar-analyze-Java-1-8-project-Failure-td5023663.html

http://jira.codehaus.org/browse/SONARJAVA-482

http://jira.codehaus.org/browse/SONARJAVA-482

Does SonarQube 4.3 support java-8?

SonarQube 4.3 是否支持 java-8?

Or any clue, what is the problem?

或者任何线索,是什么问题?

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
        at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
        at org.jacoco.agent.rt.internal_6effb9e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
        at org.jacoco.agent.rt.internal_6effb9e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:99)
        at org.jacoco.agent.rt.internal_6effb9e.PreMain.createRuntime(PreMain.java:55)
        at org.jacoco.agent.rt.internal_6effb9e.PreMain.premain(PreMain.java:47)
        ... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
        at java.lang.Class.getField(Class.java:1690)
        at org.jacoco.agent.rt.internal_6effb9e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:136)
        ... 9 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"

采纳答案by Rop

I got the missing info from the SonarQube mailing-list... To summarize:

我从 SonarQube 邮件列表中得到了缺失的信息......总结一下:

To get Java8 maven-build working on SonarQube-4.3:

要让 Java8 maven-build 在 SonarQube-4.3 上工作:

  • Install sonarqube-4.3, and start the server.

  • Login to the web-gui => Settings => Update Center => Plugins Updates => Java => Click "Upgrade to 2.2.1"

  • 安装 sonarqube-4.3,并启动服务器。

  • 登录web-gui => 设置 => 更新中心 => 插件更新 => Java => 点击“升级到 2.2.1”

Wait a minute or so for the upgrade to complete... then shutdown+restart sonarqube. Go back into the Upgrade Center and verify you have plugin: Java 2.2.1

等待一分钟左右让升级完成...然后关闭+重新启动声纳。返回升级中心并验证您有插件:Java 2.2.1

  • To get code-coverage in Sonar, you now need to build with these commands:

    mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install 
    mvn sonar:sonar
    
  • 要在 Sonar 中获得代码覆盖率,您现在需要使用以下命令进行构建:

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

Reference: http://docs.codehaus.org/display/SONAR/JaCoCo+Plugin

参考:http: //docs.codehaus.org/display/SONAR/JaCoCo+Plugin

That's it.

就是这样。

回答by Freddy - SonarSource Team

SonarQube 4.3 embeds Java plugin 2.1 whereas http://jira.codehaus.org/browse/SONARJAVA-482has been fixed in version 2.2. So by upgrading the Java plugin to version 2.2.1, this should fix your issue.

SonarQube 4.3 嵌入了 Java 插件 2.1,而http://jira.codehaus.org/browse/SONARJAVA-482已在 2.2 版中修复。因此,通过将 Java 插件升级到 2.2.1 版,这应该可以解决您的问题。

回答by Snake007uk

We had the same issue. What we did was re-install sonarqube 4.3 with Java 8 already installed. Then run analysis against sonar. If you already have sonar/java 7 installed previously and have ran analysis against it, sonar seems to install some plugins which causes these failures. If you re-install just sonar and java 8 (dont remove mysql database etc... so history is intact) - re run your analysis it seems to solve the problem with the plugins.

我们有同样的问题。我们所做的是在已经安装了 Java 8 的情况下重新安装 sonarqube 4.3。然后对声纳运行分析。如果您之前已经安装了 sonar/java 7 并对其进行了分析,那么声纳似乎安装了一些导致这些故障的插件。如果您只重新安装声纳和 java 8(不要删除 mysql 数据库等...所以历史记录是完整的) - 重新运行您的分析它似乎解决了插件的问题。

回答by Paulo Merson

I was getting the same error when mvn building a Java 1.7 project using JDK 1.8. The solution was simple: I changed the jacoco plugin versionto a newer version:

当 mvn 使用 JDK 1.8 构建 Java 1.7 项目时,我遇到了同样的错误。解决方案很简单:我将jacoco 插件版本更改为更新版本:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.6.201602180812</version>

(The project was using version 0.6.3.201306030806 before.)

(该项目之前使用的是 0.6.3.201306030806 版本。)

回答by Marcos Nunes

Here with java 11 I had this problem and I fix adding this in my gradle properties:

在这里使用 java 11 我遇到了这个问题,我修复了在我的 gradle 属性中添加它的问题:

jacoco {
  toolVersion = "0.8.2"
}

回答by Tushar Bhendarkar

If you are running jacoco with gradle them update the jacoco to latest version. I was also facing the similar issues and it got fixed after below changes

如果您使用 gradle 运行 jacoco,则将 jacoco 更新到最新版本。我也遇到了类似的问题,经过以下更改后得到修复

Java 11 and Gradle

Java 11 和 Gradle

jacoco {
    toolVersion = "0.8.4"
}

回答by Vishrant

Setting $JAVA_HOMEresolved the problem for me.

设置$JAVA_HOME为我解决了问题。