Skip to content

./gradlew build is 'Compiling and testing with Java 21' although actions/setup-java@v4 is setting Java 17 #714

Description

@GabeGiro

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:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Repro steps:

Use this ci.yml in your Android project:

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!"

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 17

Actual behavior:
Build with Gradle step shows:
Compiling and testing with Java 21

Activity

  1. mahalakshmi-rekadi commented on Dec 23, 2024

    @mahalakshmi-rekadi

    Hello @GabeGiro,
    Thank you for reporting this issue. We will investigate it and get back to you as soon as we have some feedback.

  2. v-gowridurgad commented on Dec 30, 2024

    @v-gowridurgad
    Contributor

    Hi @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?

  3. v-gowridurgad commented on Jan 10, 2025

    @v-gowridurgad
    Contributor

    Hi @GabeGiro, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.

  4. GabeGiro commented on Jan 15, 2025

    @GabeGiro
    Author

    @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

  5. v-gowridurgad commented on Jan 20, 2025

    @v-gowridurgad
    Contributor

    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:

    1. Install Gradle from the official website.
    2. Create a new project using the gradle init command.
    3. Configure the build.gradle file with necessary dependencies and plugins.
    4. 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. 

  6. v-gowridurgad commented on Jan 27, 2025

    @v-gowridurgad
    Contributor

    Hi @GabeGiro, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.

  7. v-gowridurgad commented on Feb 3, 2025

    @v-gowridurgad
    Contributor

    Hi @GabeGiro, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.

  8. GabeGiro commented on Feb 4, 2025

    @GabeGiro
    Author

    @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.

  9. v-gowridurgad commented on Feb 10, 2025

    @v-gowridurgad
    Contributor

    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 clean

    3. 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 -version
    

    4. 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.

    Image
  10. v-gowridurgad commented on Feb 21, 2025

    @v-gowridurgad
    Contributor

    Hi @GabeGiro, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.

  11. v-gowridurgad commented on Feb 28, 2025

    @v-gowridurgad
    Contributor

    Hi @GabeGiro, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.

  12. v-gowridurgad commented on Mar 10, 2025

    @v-gowridurgad
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions