SonarQube on Java8-project 给出了 jacoco-Exception

2022-09-02 09:58:26

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

  mvn clean install
  mvn sonar:sonar

这给了我下面的例外。

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

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

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

SonarQube 4.3 是否支持 java-8?

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

-------------------------------------------------------
 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"

答案 1

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

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

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

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

等待一分钟左右,以便升级完成...然后关机+重启声纳库。返回升级中心并验证您是否有插件:Java 2.2.1

  • 要在Sonar中获得代码覆盖率,您现在需要使用以下命令进行构建:

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

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

就是这样。


答案 2

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

jacoco {
  toolVersion = "0.8.4"
}

推荐