How to do analysis java 8 application with sonarqube 9.3

Must-share information (formatted with Markdown):

  • which versions are you using
    SonarQube 9.3

  • what are you trying to achieve
    Try to analysis java gradle project developed using Java 8 with gradle version 3 in azure devops pipeline.

  • what have you tried so far to achieve this
    In a command line task, I have used the command gradlew sonarqube -Dsonar.projectkey=project1 -Dsonar.host.url=https://sonarqube.abc.com Dsonar.login=*****************

But it is giving the error as “Could not determine java version from ‘11.0.13’”. As it is not possible to upgrade every application to java 11. So please let us know any workaround available to support old java application.

Hi,

You don’t have to build with Java 11. You only have to analyze with it. So your options are to use two different JREs for these two different steps, or to compile to a Java 8 target.

 
HTH,
Ann

Hi Ann, Please brief me how to do it

Hi,

The docs should help.

 
Ann

I saw this document and I am following the below two steps.

  1. Prepare Analysis Configuration Task
    Under Additional Properties I have mentioned the sonar project key.

  2. Gradle Task
    Under Advanced section I have set the JDK 8 path. Under SonarQube analysis section, I have set the “SonarQube scanner for Gradle plugin version” as 3.3

But I am getting the error as below.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:sonarqube’.

org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

Hi,

This is not about the Gradle version.

That error is telling you that you haven’t separated build and analysis, so they’re using (trying to) the same JVM: Java 8. And analysis won’t run on Java 8. You need to make this two entirely separate steps, using two different JVMs. Or you need to compile with Java 11 and set your target to 1.8.

 
HTH,
Ann

Hi Ann,

As you mentioned I have added two gradle task. One for build with JDK 8 and one for analysis with JDK11. But I am getting the error as below

FAILURE: Build failed with an exception.

  • What went wrong:
    Could not determine java version from ‘11.0.13’.

In the In gradle-wrapper.properties, gradle version is mentioned as 3. If I increase the gradle version to higher, the code was not building. So without gradle task, do we have any option to scan Java 8 code so I don’t require to increase the gradle version?

Thanks.

Hi,

I’m not a Gradle expert, so I can’t sort that out for you. What I know is that you can use Java 11 to build to a Java 8 target.

 
Ann