Repository navigation
./gradlew build is 'Compiling and testing with Java 21' although actions/setup-java@v4 is setting Java 17 #714
Description
Activity
Hello @GabeGiro,
Thank you for reporting this issue. We will investigate it and get back to you as soon as we have some feedback.Reacted by Gabe GiroHi @GabeGiro, After replicating the issue using the provided workflow, we found that everything is working as expected. The Build with Gradle step is correctly compiling and testing with Java 17. For your reference, we’ve included link of the successful run. To assist us in further investigating, could you please share a link to the build or a public repository where the issue can be reproduced?
Hi @GabeGiro, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.
@gowridurgad I'm not going to work on this issue for at least 3 more weeks. Although I saw your successful build I'm curious what is the difference between our gradle files. I'm working with a mature Android project (few years) so there is 100% chance something is different and unfortunately Android builds don't have containerisation - hence it works on yours but not on mine.
Again, I will not work on this any time soon but if you can share your process in the meantime, that would be useful. Did you start you Android project from scratch, did you use Android Studio's empty project, are you using old or new gradle files?
And I will write all these for my project in few weeks.Thank you in advance
Hi @GabeGiro, Android Gradle files include Android-specific plugin configurations, dependencies, and build configurations, while normal Gradle files are typically used for Java or other JVM-based projects without Android-specific configurations. we are using simple application using new Gradle files specific to our setup. To generate Gradle files:
- Install Gradle from the official website.
- Create a new project using the gradle init command.
- Configure the build.gradle file with necessary dependencies and plugins.
- Run Gradle tasks like gradle build and gradle test to manage your project.
For more detailed steps, refer to the official documentation on Building and testing Java with Gradle.
Hi @GabeGiro, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.
Hi @GabeGiro, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.
@gowridurgad thank you for sharing the link but it's not useful here. We are talking about Android-specific project. As mentioned before, I would appreciate if you shared some Android project files that enable you to build with Java 17.
Here is my setup:
.github/workflows/ci.yml:
name: CI on: pull_request: branches: - main - dev push: branches: - main - dev jobs: build: runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v4 - name: Set up JDK 17 uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: '17' - name: Cache Gradle packages uses: actions/cache@v4 with: path: | ~/.gradle/caches ~/.gradle/wrapper/ key: ${{ runner.os }}-gradle-v1-${{ hashFiles('**/build.gradle', '**/build.gradle.kts', '**/settings.gradle', '**/settings.gradle.kts', '**/gradle.lockfile') }} restore-keys: | ${{ runner.os }}-gradle-v1- - name: Grant execute permission for Gradle Wrapper run: chmod +x ./gradlew - name: Build with Gradle run: ./gradlew build - name: Run Unit Tests run: ./gradlew test - name: Notify Success if: success() run: echo "Build and tests passed!" - name: Notify Failure if: failure() run: echo "Build or tests failed!"Part of app's build.gradle:
android { namespace 'com.name' compileSdk 34 defaultConfig { applicationId "com.name" minSdk 29 targetSdk 34 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { arguments "-DOPENCV_VERSION_MAJOR=4", "-DOPENCV_FROM_SDK=FALSE", "-DANDROID_STL=c++_shared" targets "native_lib" } } } ktlint { android = true ignoreFailures = false disabledRules = ["wildcard-imports", "no-wildcard-imports"] reporters { reporter "plain" reporter "checkstyle" //reporter "sarif" //reporter "html" } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } composeOptions { kotlinCompilerExtensionVersion '1.5.1' } packagingOptions { exclude 'META-INF/DEPENDENCIES' } externalNativeBuild { cmake { path 'src/main/cpp/CMakeLists.txt' } } buildFeatures { compose true prefab true // Enable prefab for OpenCV } }Please, let me know if I can share anything else that will help you solve this.
Hi @GabeGiro, Thank you for providing detailed information about your setup. We tested this workflow with an Android project, specifically using Android Input Samples, and it worked correctly with Java 17. For reference, we have attached a screenshot of the successful build showing that the Gradle step is compiling and testing with Java 17.
Here are some troubleshooting steps that might help resolve your issue:
1. Verify Gradle Wrapper Version: Ensure that the Gradle wrapper version in your project supports Java 17. Update it to the latest compatible version if necessary by running:./gradlew wrapper --gradle-version <latest-supported-version>2. Clean Gradle Cache: Since Gradle caching can sometimes cause unexpected issues, try clearing the cache before running the build:
./gradlew clean3. Set JAVA_HOME: Confirm that the JAVA_HOME variable points to JDK 17. Add a step to verify with:
- name: Check Java Version run: java -version4. Update Android Gradle Plugin: Verify that your Android Gradle plugin version is compatible with Java 17. You might need to update the plugin in your build.gradle file:
classpath "com.android.tools.build:gradle:<latest-compatible-version>"If the issue persists, consider replicating it in a smaller, newly created Android project to help narrow down the cause. Let us know if these steps resolve the problem or if there's anything else we can assist you with.

Hi @GabeGiro, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.
Hi @GabeGiro, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.
Hi @GabeGiro, Due to inactivity, I'm going to close this issue for now. Please feel free to reopen this issue or create a new one if necessary. Thank you.
Description:
./gradlew build is 'Compiling and testing with Java 21' after actions/setup-java@v4 is setting Java 17.
I tried a lot of things:
Task version:
v3 and v4
Platform:
Runner type:
Repro steps:
Use this ci.yml in your Android project:
Note: I commented out the cache for the purpose of making sure that I'm not reusing gradle files
Expected behavior:
Build with Gradle step should show:
Compiling and testing with Java 17Actual behavior:
Build with Gradle step shows:
Compiling and testing with Java 21