New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect JDKs provisioned by Github actions automatically #14903
Comments
This feature would be very useful to me. The runners hosted by GitHub seem to have a Hosted Tool Cache with some JDKs preinstalled. An example path to a JDK in the cache is:
So the pattern seems to be something like:
The path to the tool cache directory resides in the environment variable However, the Please let me know if I can help in any way. |
While I didn't solve this issues "automatically", there is a way to point gradle at it: - name: Setup JDK
id: setup-java-8
uses: actions/setup-java@v2.2.0
with:
distribution: 'zulu'
java-version: '8'
...
- name: Setup gradle properties
run: |
echo "org.gradle.java.installations.paths=${{ steps.setup-java-8.outputs.path }}" >> gradle.properties |
Gradle will by default use the same JDK for building the project as it does for running Gradle. Newer JDKs are assumed to be more performant, contain fewer bugs and to come with desirable features that we would like to utilize in our build, but doing so should not endanger backwards compatibility for the plugin itself. We can do that now by utilizing Gradle toolchains, which allows us to use one JDK/JRE for running Gradle and the other for building the project, i.e. executing `javac`. Doing this requires us to make multiple JDKs available to the Gradle build action for each individual execution of the build. The setup-java action doesn't support this at the moment, and the multiple build steps configured for actions/setup-java in this commit is at best a workaround for this, and at worst a bad assumption with respect to no environment variables or other settings being overwritten. Also, there's no handling of duplicate invocations of the action with the end result being duplicate JDKs installed. Hopefully both actions/setup-java and gradle/gradle-build-action will handle this case gracefully. For more details, see: - actions/setup-java#44 - gradle/gradle#14903
Gradle will by default use the same JDK for building the project as it does for running Gradle. Newer JDKs are assumed to be more performant, contain fewer bugs and to come with desirable features that we would like to utilize in our build, but doing so should not endanger backwards compatibility for the plugin itself. We can do that now by utilizing Gradle toolchains, which allows us to use one JDK/JRE for running Gradle and the other for building the project, i.e. executing `javac`. Doing this requires us to make multiple JDKs available to the Gradle build action for each individual execution of the build. The setup-java action doesn't support this at the moment, and the multiple build steps configured for actions/setup-java in this commit is at best a workaround for this, and at worst a bad assumption with respect to no environment variables or other settings being overwritten. Also, there's no handling of duplicate invocations of the action with the end result being duplicate JDKs installed. Hopefully both actions/setup-java and gradle/gradle-build-action will handle this case gracefully. For more details, see: - actions/setup-java#44 - gradle/gradle#14903
This commit decouples the JDK running Gradle from the one building the project. Gradle will by default use the same JDK for building the project as it does for running Gradle. Newer JDKs are assumed to be more performant, contain fewer bugs and to come with desirable features that we would like to utilize in our build, but doing so should not endanger backwards compatibility for the plugin itself. We can do that now by utilizing Gradle toolchains, which allows us to use one JDK/JRE for running Gradle and the other for building the project, i.e. executing `javac`. Doing this requires us to make multiple JDKs available to the Gradle build action for each individual execution of the build. The setup-java action doesn't support this at the moment, and the multiple build steps configured for actions/setup-java in this commit is at best a workaround for this, and at worst a bad assumption with respect to environment variables or other settings being overwritten. Furthermore, there's no handling of duplicate invocations of the action. Hopefully both actions/setup-java and gradle/gradle-build-action will handle all of this gracefully. For more details, see: - actions/setup-java#44 - gradle/gradle#14903
This commit decouples the JDK running Gradle from the one building the project. Gradle will by default use the same JDK for building the project as it does for running Gradle. Newer JDKs are assumed to be more performant, contain fewer bugs and to come with desirable features that we would like to utilize in our build, but doing so should not endanger backwards compatibility for the plugin itself. We can do that now by utilizing Gradle toolchains, which allows us to use one JDK/JRE for running Gradle and the other for building the project, i.e. executing `javac`. Doing this requires us to make multiple JDKs available to the Gradle build action for each individual execution of the build. The setup-java action doesn't support this at the moment, and the multiple build steps configured for actions/setup-java in this commit is at best a workaround for this, and at worst a bad assumption with respect to environment variables or other settings being overwritten. Furthermore, there's no handling of duplicate invocations of the action. Hopefully both actions/setup-java and gradle/gradle-build-action will handle all of this gracefully. For more details, see: - actions/setup-java#44 - gradle/gradle#14903
This commit decouples the JDK running Gradle from the one building the project. Gradle will by default use the same JDK for building the project as it does for running Gradle. Newer JDKs are assumed to be more performant, contain fewer bugs and to come with desirable features that we would like to utilize in our build, but doing so should not endanger backwards compatibility for the plugin itself. We can do that now by utilizing Gradle toolchains, which allows us to use one JDK/JRE for running Gradle and the other for building the project, i.e. executing `javac`. Doing this requires us to make multiple JDKs available to the Gradle build action for each individual execution of the build. The setup-java action doesn't support this at the moment, and the multiple build steps configured for actions/setup-java in this commit is at best a workaround for this, and at worst a bad assumption with respect to environment variables or other settings being overwritten. Furthermore, there's no handling of duplicate invocations of the action. Hopefully both actions/setup-java and gradle/gradle-build-action will handle all of this gracefully. For more details, see: - actions/setup-java#44 - gradle/gradle#14903
This commit decouples the JDK running Gradle from the one building the project. Gradle will by default use the same JDK for building the project as it does for running Gradle. Newer JDKs are assumed to be more performant, contain fewer bugs and to come with desirable features that we would like to utilize in our build, but doing so should not endanger backwards compatibility for the plugin itself. We can do that now by utilizing Gradle toolchains, which allows us to use one JDK/JRE for running Gradle and the other for building the project, i.e. executing `javac`. Doing this requires us to make multiple JDKs available to the Gradle build action for each individual execution of the build. The setup-java action doesn't support this at the moment, and the multiple build steps configured for actions/setup-java in this commit is at best a workaround for this, and at worst a bad assumption with respect to environment variables or other settings being overwritten. Furthermore, there's no handling of duplicate invocations of the action. Hopefully both actions/setup-java and gradle/gradle-build-action will handle all of this gracefully. For more details, see: - actions/setup-java#44 - gradle/gradle#14903
Are there any plans to move this forward? This is what makes me reluctant to use JVM toolchains. Note that the setup-java action is instant when using the |
The issue is in the backlog of the relevant team, but this area of Gradle is currently not a focus one, so it might take a while before a fix is made. |
Ok thanks for providing a status, I'm looking forward to this! 🙏 |
About this:
It looks like those are 2 different features. I believe Gradle could by default look into the default hosted tool cache of GitHub runners, but not necessarily be aware of specific GitHub actions (like setup-java) and where they place things (as this path is technically dynamic and can be retrieved as an output of the setup-java action). |
As a workaround, GitHub currently provides env variables for the Java home of the all current LTS versions:
Now that I think of it, maybe GitHub could provide such a default If GitHub pre-installed some Gradle (not the case now) and put this property in the Gradle installation dir, would this affect projects that use the Gradle wrapper? (it might be worth clarifying this in the docs, by the way) |
@joffrey-bion That's a great idea! If it can be resolved at the action level, it would be nice.
Yes, that is correct, however, it can be overridden again by a command line. I don't think it's a big problem.
It shouldn't matter how Gradle is invoked: as local |
Regarding the gradle action, PTAL at the issue there |
The idea here is user preferences should have higher priority than project preferences. So CLI has a clear intent, then user preferences, project preferences, and lastly, "system" preferences. |
Well it is definitely a problem if GitHub were to define some properties in the home dir of the runners, because users setting
While I see the point, I never ever needed to express it this way. But every single time I wanted to express user defaults, hoping to override them in a per-project basis... and it doesn't work this way.
If it doesn't matter how Gradle is run, does that mean that my Anyway, this whole topic is out of scope for this discussion, sorry for the off topic, I just wanted to confirm that GitHub cannot and thus shouldn't try to do this. |
Oh, I forgot about this action. It could definitely be provided as an extra CLI argument by default in this GitHub action, I'll head over to that issue. Thanks! |
No, they would be overridden, not ignored. And it only applies to settings set by action, not all settings. As for your use case - let's jump into a separate issue. I think there is a clear need to have better documentation in this area. Would you like to create a documentation issue with a list of stuff that should be clarified in that area? |
Yes, I was unclear about this. The problem is still there, though. GitHub cannot set this property as a default without overriding the same property defined at the project level by some users.
I opened the following: |
I've done some testing, and toolchain detection is now mostly working on GitHub Actions runners, without any special handling in the There are 2 types of JDKs that can be detected on a runner:
On On So as long as I will attempt to update the I think it's safe to close this issue, since this is something that should be fixed in the GitHub Runner (or the |
We should have a look at common actions on GitHub actions that provision JDKs.
If we can find a pattern, we may be able to automatically detect those without additional setup
Example:
actions/setup-java@v1
The text was updated successfully, but these errors were encountered: