Maven Build Java 8, SonarCloud java 11

,
  • ALM used: Bitbucket Cloud
  • CI system used AWS CodeBuild
  • Scanner command used when applicable: mvn --settings aws/settings.xml sonar:sonar -e -Dskip.unit.tests=true -Dsonar.verbose=true -X -Dsonar.login=$LOGIN -Dsonar.host.url=$HOST -Dsonar.projectKey=$Project -Dsonar.organization=$Organization
  • Languages of the repository: Java

Hi,
I have this Java project that is build in Java8 (not compatible with Java11), but I understand that SonarCloud accept only Java11 as runtime version.
I read a lot of topics as this one but I cannot find any solution.

Now I build in a step with java8 my project with:

mvn --settings aws/settings.xml clean install -P-validateCode 

Then I try to run this command that from doc seems work with java8:

mvn verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.login=$LOGIN -Dsonar.host.url=$HOST -Dsonar.projectKey=$Project -Dsonar.organization=$Organization -X

But It fails with the following error:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar (default-cli) on project athena: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar: java.lang.UnsupportedClassVersionError: 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

It seems that it needs also here Java11

So I have created a new step with java11 that take the source from the previous step (where the project is correctly compiled in java8) and I tried to run the following commands:

mvn verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.login=$LOGIN -Dsonar.host.url=$HOST -Dsonar.projectKey=$Project -Dsonar.organization=$Organization -X
mvn --settings aws/settings.xml sonar:sonar -e -Dsonar.verbose=true -X -Dsonar.login=$LOGIN -Dsonar.host.url=$HOST -Dsonar.projectKey=$Project -Dsonar.organization=$Organization

It keeps failing, the last command fails with this error:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar (default-cli) on project athena: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar (default-cli) on project athena: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property.

My project is a multiple module project, the “mvn verify” is success on all modules except for the root one (if it is run on java8)
The “mvn sonar:sonar” fails in the root module and then it skips all the others.

How can I exclude the root module?

1 Like

Based on the code snippets in your post, it doesn’t look like you are following the doc you linked. The point in that doc is to use the first command to build the project and run its tests (mvn verify) with your version of Java (Java 8), and then use the second command just with the sonar:sonar goal.

Based on your code snippets, I think the commands you’re looking for should be more like this:

# using Java 8
mvn --settings aws/settings.xml clean install -P-validateCode

# using Java 11 -- notice NO "verify" here
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.login=$LOGIN -Dsonar.host.url=$HOST -Dsonar.projectKey=$Project -Dsonar.organization=$Organization -X
1 Like

Hi,
the problem is that I cannot run both commands in the same pipeline step.
I solved split it in 2 steps with different java versions and the sonar analisys is due on the source could without any build before.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.