Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does SonarQube support Java 8 yet?

With Java 8, executing gradle sonarRunner shows this error message. (sonarQube version : 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]
```

Does SonarQube not support Java 8 yet? I would like to know when support is available.

Thank you.

like image 927
xyzlast Avatar asked Mar 19 '14 05:03

xyzlast


People also ask

What version of Java does SonarQube supports?

Java. The SonarQube server require Java version 11 and the SonarQube scanners require Java version 11 or 17. SonarQube is able to analyze any kind of Java source files regardless of the version of Java they comply to. We recommend using the Critical Patch Update (CPU) releases.

Does SonarQube support Java 17?

In SonarQube 9.4, Java 17 is supported for running analysis, and parsing of Java 18 code (and 17, too) is also supported. Regarding the version of Java your code runs with, as long as you analyze with a supported version of Java, you can compile with or to whatever version of Java you like.

How do I run SonarQube with Java 11?

Set Execute SonarQube Scanner JDK version If you're using the Execute SonarQube Scanner step in your configuration, you can set the JDK for this step in the configuration dialog. This allows you to use JDK 11 for the code scanning performed by SonarQube and the globally configured JDK for all other steps in the job.


1 Answers

SonarQube supports Java 8 since end of March 2014 (with some hickups at first, which were fixed in version 2.2 of its Java plugin).

I had to uninstall the PMD and Checkstyle plugins in Sonar's update center as those are not ready for Java 8. Sonar's own rule engine Squid should make those plugins redundant anyway.


If you are using Gradle 1.11 to call Sonar and want Jacoco to calculate code coverage, you'll have to specify the latest Jacoco version in order to analyze Java 8 bytecode.

Here's my script that does that when called with 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
    }
}
like image 108
Matthias Braun Avatar answered Oct 04 '22 15:10

Matthias Braun