SonarQube现在支持Java 8吗?

11

使用Java 8执行gradle sonarRunner会显示此错误消息。 (sonarQube版本:4.2.1)

java.lang.ArrayIndexOutOfBoundsException: 26721
    at org.objectweb.asm.ClassReader.readClass(Unknown Source) [asm-all-3.2.jar:5.0_BETA]
    at org.objectweb.asm.ClassReader.accept(Unknown Source) [asm-all-3.2.jar:5.0_BETA]
    at org.objectweb.asm.ClassReader.accept(Unknown Source) [asm-all-3.2.jar:5.0_BETA]
    at org.sonar.java.bytecode.asm.AsmClassProviderImpl.decoracteAsmClassFromBytecode(AsmClassProviderImpl.java:76) [java-squid-2.0.jar:na]
    at org.sonar.java.bytecode.asm.AsmClassProviderImpl.getClass(AsmClassProviderImpl.java:55) [java-squid-2.0.jar:na]
    at org.sonar.java.bytecode.asm.AsmClassVisitor.visit(AsmClassVisitor.java:52) [java-squid-2.0.jar:na]
    at org.objectweb.asm.ClassReader.accept(Unknown Source) [asm-all-3.2.jar:5.0_BETA]
    at org.objectweb.asm.ClassReader.accept(Unknown Source) [asm-all-3.2.jar:5.0_BETA]
```

SonarQube还不支持Java 8吗?我想知道何时会提供支持。

谢谢。


3
你应该向该项目的邮件列表询问,不是吗? - sjr
2
这个问题似乎不适合讨论,因为它涉及到SonarCube的演进时间线。 - user180100
3个回答

12

SonarQube 支持 自2014年3月底以来的Java 8(虽然一开始有问题, 但这些问题在其Java插件的2.2版本中已得到解决)。

我不得不在Sonar的更新中心中卸载PMD和Checkstyle插件,因为它们尚未准备好适用于Java 8。 Sonar自己的规则引擎Squid应该使那些插件变得多余。


如果您正在使用Gradle 1.11调用Sonar并想要Jacoco计算代码覆盖率,您需要指定最新的Jacoco版本以分析Java 8字节码。 以下是我的脚本,当使用gradle test jacocoTestReport sonarRunner调用时会执行该操作:
/** This script is responsible for unit testing and static analysis of the project source code*/

apply plugin: "jacoco"
apply plugin: "sonar-runner"

// Location of the XML unit test and code coverage reports 
def testResultsDir = "$buildDir/test-results/" // Use double quotes. Otherwise the $ won't work

jacoco{
    // Gradle 1.11 ships with a Jacoco version that doesn't support Java 8
    toolVersion = "0.7.0.201403182114"
}
// Call "gradle test jacocoTestReport" to produce a code coverage report at "build/reports/jacoco/test/html/index.html"
test {
    jacoco {
        def coverageReport = new File(testResultsDir, "jacocoTest.exec")
        destinationFile = file(coverageReport)
    }
}

// Let SonarQube analyze the project
sonarRunner {
    sonarProperties {
        property "sonar.projectKey", projectId
        property "sonar.projectName", projectName

        property "sonar.junit.reportsPath", testResultsDir

        // Address of SonarQube server
        property "sonar.host.url", "http://localhost:9000"

        // SonarQube stores the test results in this database
        property "sonar.jdbc.url", "jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true"
        property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver"
        property "sonar.jdbc.username", "root"
        property "sonar.jdbc.password", sonarDBpassword
    }
}

我通过更新中心升级到了2.2.1版本,针对一个Java8项目运行命令:mvn sonar:sonar。但问题仍然存在:它没有显示任何单元测试覆盖率,只有一个破折号代替了百分比。有什么线索吗? - Rop
@Rop:你使用Jacoco来进行代码覆盖率测试吗?如果是的话,请确保你使用的是支持Java 8的Jacoco版本。 - Matthias Braun
我刚刚安装了SonarQube-4.3,并进行了Update Center升级到java-2.2.1。还需要做些什么吗? 这里是我在安装目录中找到的Jacoco文件: ./extensions/plugins/sonar-jacoco-plugin-2.2.1.jar ./lib/bundled-plugins/sonar-jacoco-plugin-2.1.jar ./web/deploy/plugins/jacoco/META-INF/lib/asm-debug-all-5.0.jar ./web/deploy/plugins/jacoco/META-INF/lib/org.jacoco.agent-0.7.0.201403182114.jar ./web/deploy/plugins/jacoco/META-INF/lib/org.jacoco.core-0.7.0.201403182114.jar ./web/deploy/plugins/jacoco/sonar-jacoco-plugin-2.2.1.jar - Rop
@Rop:最好你开一个新的问题来讨论,而不是在评论中讨论。 - Matthias Braun
在Java8项目上运行SonarQube会导致Jacoco异常。 - Rop

4
你的问题有两个方面:
  1. sonarRunner(客户端)
  2. SonarQube应用程序(服务器端)
你收到的错误来自于在客户端下载并依赖于旧版本ASM(3.2)的Java生态系统插件。据我所知,Java 8支持从版本5.0开始。Findbugs和Jacoco也会出现同样的问题。请参见此讨论
关于SonarQube服务器,你可以启动它,但当你选择“配置小部件”时,它会崩溃,所以我认为它还不支持Java 8。

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接