gradle / gradle-build-action

Execute your Gradle build and trigger dependency submission
https://github.com/marketplace/actions/gradle-build-action
MIT License
679 stars 97 forks source link

Setup Java Environment functionality with a parameter #852

Closed mustafaozhan closed 11 months ago

mustafaozhan commented 1 year ago

I was wondering if we can put java setup into gradle-build-action with an extra parameter. I don't know if it is possible according to GitHub action rules and limitations.

So currently, people with Java/Kotlin & Android world has to do this:

      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          java-version: 17
          distribution: 'temurin'

      - name: Assemble
        uses: gradle/gradle-build-action@v2.7.0
        with:
          arguments: assemble

But If we could add a parameter to gradle-build-action ie java-version: X and when this is applied gradle-build-action can apply the actions/setup-java@v3 under the hood.

      - name: Assemble
        uses: gradle/gradle-build-action@v2.7.0
        with:
          java-version: 17
          arguments: assemble

This will allow us having less lines of codes in GitHub Action yml files.

bigdaz commented 1 year ago

This is an interesting idea, but I'm not sure it's easy to do or even necessary.

In general, there are 2 reasons that you might want to use setup-java to configure a JDK.

  1. So that your Gradle Build logic runs on a particular JDK
  2. So that your Java/Kotlin sources are compiled and tested with a particular JDK

I suspect that in the vast majority of cases, it's the second reason that's driving the use of setup-java. But Gradle offers a better way to do this: specify the Java Toolchain version in your build logic. Java Toolchains tell Gradle which JDK to use for compiling sources and executing tests, and are supported by core Gradle plugins, as well as AGP and KGP.

So before adding any sort of java-version support to the gradle-build-action, I'd rather first address #561, and encourage users to leverage Java Toolchains to control the JDK for their build.

After that, we should consider if it's often necessary to use setup-java at all, or if Gradle can run effectively on the default Java installed on each GitHub Actions runner.

bigdaz commented 11 months ago

We don't plan to add setup-java functionality to this action.