We have Maven/Gradle projects which use Java 8 to built-in using GitHub actions. Now we updated the SonarQube version to 9.9. How we can set up the GitHub Action yaml file to build Java 8 project? I have gone through this document but there is no example for Java 8 project for GitHub Actions.
if I set java-version to 8 it builds but the sonar scan fails because it requires java 11.
Can you please help?
Yes, I tried with javac.
Github action yaml file I set up Java 8 and Java 11 as shown in the logs.
Also, I tried to set up -Dsonar.java.jdkHome= with both Java paths.
Logs
Run actions/setup-java@v3
Installed distributions
Trying to resolve the latest version from remote
Resolved latest version as 11.0.18+10
Trying to download...
Downloading Java 11.0.18+10 (Adopt-Hotspot) from https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.18%2B10/OpenJDK11U-jdk_x64_linux_hotspot_11.0.18_10.tar.gz ...
Extracting Java archive...
/usr/bin/tar xz --warning=no-unknown-keyword -C /home/ec2-user/actions-runner/_work/_temp/1598058e-694d-4afd-9666-6952f203774f -f /home/ec2-user/actions-runner/_work/_temp/4b82bcf3-77e7-4bff-aa5c-ada33c7568e3
Java 11.0.18+10 was downloaded
Setting Java 11.0.18+10 as the default
Creating toolchains.xml for JDK version 11 from adopt
Writing to /home/ec2-user/.m2/toolchains.xml
Java configuration:
Distribution: adopt
Version: 11.0.18+10
Path: /home/ec2-user/actions-runner/_work/_tool/Java_Adopt_jdk/11.0.18-10/x64
Trying to resolve the latest version from remote
Resolved latest version as 8.0.362+9
Trying to download...
Downloading Java 8.0.362+9 (Adopt-Hotspot) from https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u362-b09/OpenJDK8U-jdk_x64_linux_hotspot_8u362b09.tar.gz ...
Extracting Java archive...
/usr/bin/tar xz --warning=no-unknown-keyword -C /home/ec2-user/actions-runner/_work/_temp/6a020496-bb18-4e53-8a66-554c164cfe11 -f /home/ec2-user/actions-runner/_work/_temp/f6b0752b-edaa-4733-87c0-5636db9cb7c7
Java 8.0.362+9 was downloaded
Setting Java 8.0.362+9 as the default
Creating toolchains.xml for JDK version 8 from adopt
Overwriting existing file /home/ec2-user/.m2/toolchains.xml
Java configuration:
Distribution: adopt
Version: 8.0.362+9
Path: /home/ec2-user/actions-runner/_work/_tool/Java_Adopt_jdk/8.0.362-9/x64
Creating settings.xml with server-id: github
Writing to /home/ec2-user/.m2/settings.xml
maven cache is not found
Still, I am getting this error.
Downloaded from internal-repository: https://nexus.nee.com/repository/maven-public/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar (262 kB at 935 kB/s)
[INFO] User cache: /home/ec2-user/.sonar/cache
[INFO] SonarQube version: 9.9.0.65466
[INFO] Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 47.114 s
[INFO] Finished at: 2023-03-06T21:18:12Z
[INFO] Final Memory: 55M/7851M
[INFO] ------------------------------------------------------------------------
Error: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project tb-volume-import-mv90: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184: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
Error: -----------------------------------------------------
Error: realm = plugin>org.codehaus.mojo:sonar-maven-plugin:3.9.1.2184
Error: strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
Error: urls[0] = file:/home/ec2-user/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/3.9.1.2184/sonar-maven-plugin-3.9.1.2184.jar
Error: urls[1] = file:/home/ec2-user/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
Error: urls[2] = file:/home/ec2-user/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
Error: urls[3] = file:/home/ec2-user/.m2/repository/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar
Error: urls[4] = file:/home/ec2-user/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/2.16.2.588/sonar-scanner-api-2.16.2.588.jar
Error: urls[5] = file:/home/ec2-user/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
Error: Number of foreign imports: 1
Error: import: Entry[import from realm ClassRealm[maven.api, parent: null]]
Yes, I tried Felipe’s example.
But we are using the maven wrapper to build and analyze the project.
Here is the command which we are using in GitHub actions yaml and the wrapper file.