# Github Actions for Java 8 Maven/Gradle Projects

**URL:** <https://community.sonarsource.com/t/github-actions-for-java-8-maven-gradle-projects/84985>\
**Category:** SonarQube Server / Community Build\
**Tags:** java11, maven, gradle, sonarqube, scanner\
**Created:** [March 1, 2023, 1:52pm UTC](https://community.sonarsource.com/t/github-actions-for-java-8-maven-gradle-projects/84985 "2023-03-01T13:52:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zorro](https://avatars.discourse-cdn.com/v4/letter/z/ad7895/32.png) [@zorro](https://community.sonarsource.com/u/zorro)\
**Post date:** [March 1, 2023, 1:52pm UTC](https://community.sonarsource.com/t/github-actions-for-java-8-maven-gradle-projects/84985/1 "2023-03-01T13:52:40Z")

</div>

**SonarQube 9.9 LTS Version**

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?

[![](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/5/7/57bcc4fcc93d9d91d02af155c058e6d548ce30dd.png)GitHub integration](https://docs.sonarqube.org/latest/devops-platform-integration/github-integration/#:~:text=Click%20the%20scanner%20you%27re%20using%20below%20to%20expand%20the%20example%20configuration%3A)

---

<div class="post-metadata">

**Author:** ![zorro](https://avatars.discourse-cdn.com/v4/letter/z/ad7895/32.png) [@zorro](https://community.sonarsource.com/u/zorro)\
**Post date:** [March 1, 2023, 7:56pm UTC](https://community.sonarsource.com/t/github-actions-for-java-8-maven-gradle-projects/84985/2 "2023-03-01T19:56:30Z")

</div>

Hi,

Any one help me with this?

---

<div class="post-metadata">

**Author:** ![zorro](https://avatars.discourse-cdn.com/v4/letter/z/ad7895/32.png) [@zorro](https://community.sonarsource.com/u/zorro)\
**Post date:** [March 3, 2023, 6:19pm UTC](https://community.sonarsource.com/t/github-actions-for-java-8-maven-gradle-projects/84985/3 "2023-03-03T18:19:41Z")

</div>

Hi @Colin @ganncamp

I am sorry for tagging,  
Can you please help me here?

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 3, 2023, 6:25pm UTC](https://community.sonarsource.com/t/github-actions-for-java-8-maven-gradle-projects/84985/4 "2023-03-03T18:25:43Z")

</div>

Hi,

Have you tried building _to_ Java 8 using the `-target` flag on `javac`?

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![felipebz](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/felipebz/32/32739_2.png) [@felipebz](https://community.sonarsource.com/u/felipebz)\
**Post date:** [March 3, 2023, 8:54pm UTC](https://community.sonarsource.com/t/github-actions-for-java-8-maven-gradle-projects/84985/5 "2023-03-03T20:54:30Z")

</div>

You can continue using Java 8 to build your project and use Java 11 or 17 to run the SonarScanner.

Here’s an example based on [GitHub integration](https://docs.sonarqube.org/latest/devops-platform-integration/github-integration/)

```auto
name: Build
on:
  push:
    branches:
      - main # the name of your main branch
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
		  
      - name: Set up JDK 8
        uses: actions/setup-java@v1
        with:
          java-version: 8
	
      - name: Build
        run: mvn -B verify
		  
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11
	
      - name: Analyze
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
        run: mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

```

---

<div class="post-metadata">

**Author:** ![zorro](https://avatars.discourse-cdn.com/v4/letter/z/ad7895/32.png) [@zorro](https://community.sonarsource.com/u/zorro)\
**Post date:** [March 6, 2023, 9:27pm UTC](https://community.sonarsource.com/t/github-actions-for-java-8-maven-gradle-projects/84985/6 "2023-03-06T21:27:46Z")

</div>

Hi @ganncamp @felipebz

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**

```auto
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.

```auto
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]]

```

---

<div class="post-metadata">

**Author:** ![zorro](https://avatars.discourse-cdn.com/v4/letter/z/ad7895/32.png) [@zorro](https://community.sonarsource.com/u/zorro)\
**Post date:** [March 8, 2023, 6:56pm UTC](https://community.sonarsource.com/t/github-actions-for-java-8-maven-gradle-projects/84985/7 "2023-03-08T18:56:34Z")

</div>

Hi @ganncamp

Can you please help?

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 8, 2023, 7:02pm UTC](https://community.sonarsource.com/t/github-actions-for-java-8-maven-gradle-projects/84985/8 "2023-03-08T19:02:22Z")

</div>

Hi,

> [@zorro](#):
>
> `Error: ... An API incompatibility was encountered ... 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`

You’re still running analysis with the wrong version of Java.

And the first log snippet shows that:

> [@zorro](#):
>
> ```auto
> 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
> 
> ```

Did you try Felipe’s example?

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![zorro](https://avatars.discourse-cdn.com/v4/letter/z/ad7895/32.png) [@zorro](https://community.sonarsource.com/u/zorro)\
**Post date:** [March 9, 2023, 9:05pm UTC](https://community.sonarsource.com/t/github-actions-for-java-8-maven-gradle-projects/84985/9 "2023-03-09T21:05:06Z")

</div>

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.

```auto
      - name: Build
        working-directory: src/volumeImporterLambda
        run: |
           ./mvnw -X \
            --settings settings.xml \
            clean \
            install \
            -Dsonar.java.jdkHome=/home/ec2-user/actions-runner/_work/_tool/Java_Zulu_jdk/8.0.362-9/x64 \
            -Dsonar.host.url=${{ secrets.SONARQUBE_HOST2 }} \
            -Dsonar.login=${{ secrets.SONARQUBE_TOKEN2 }}

```

[mvnw.txt](https://community.sonarsource.com/uploads/short-url/faMtYdv9eE8nTCSrthXattvv2XM.txt) (10.0 KB)
