SonarQube是否支持Java 8?

xyz*_*ast 11 java java-8 sonarqube

使用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]
```
Run Code Online (Sandbox Code Playgroud)

SonarQube不支持Java 8吗?我想知道什么时候有支持.

谢谢.

Mat*_*aun 12

SonarQube 从2014年3月底开始支持 Java 8(最初有一些hickup,在其Java插件的2.2版本中得到修复).

我不得不卸载Sonar更新中心的PMD和Checkstyle插件,因为它们还没有为Java 8做好准备.声纳自己的规则引擎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
    }
}
Run Code Online (Sandbox Code Playgroud)