thriving-dev / java-library-template

🎨 Java library template β€’ Gradle Kotlin DSL β€’ GitHub Actions CI/CD to build, release & publish to Maven Central β€’ Renovate β€’ Trivy β€’ Javadoc (Pages) β€’ Issue & PR Templates
https://www.youtube.com/watch?v=nXs7hSV6ris&list=PL1tfxqbktkFYK5zYjfHxt4wFOus5R9Y3g&index=1
Other
31 stars 4 forks source link

Use JVM Toolchain #32

Open StefMa opened 8 months ago

StefMa commented 8 months ago

❓ Type of change

πŸ“š Description, Motivation and Context

This PR moves the JVM Version selection from the machine to the build time. With that change, Gradle makes sure that the code will be compiled with the configured JVM ersion (21) from the configured vendor (Corretto/Amazon). There is "no need" to install a specific JVM version on CI or your dev machine. You only need "a" JVM installation that can start Gradle. Gradle will detect that the configuration say it should compile the code with Java 21/Corretto, it will install the respective toolchain and use that to compile the code and run tests with that.

More information can also be found here: https://docs.gradle.org/8.6/userguide/toolchains.html

πŸ§ͺ How Has This Been Tested?

Remove your locally installed JVM version (21/Corretto). Then use another JVM version and kick of Gradle (./gradlew check). Wihin the configuration phase you will see an output like this: Screenshot 2024-03-07 at 9 02 37β€―AM Indicating that the requested toolchain (was donwloaded) and now installing on the machine for later usage.

πŸ“ Checklist

hartmut-co-uk commented 8 months ago

Thanks, @StefMa, for submitting this PR! I'll need to look closer at the gradle docs. But at first glance, this seems like a valid and useful addition.

StefMa commented 5 months ago

Hey @hartmut-co-uk, any chance to have a look at this?

StefMa commented 5 months ago

So the data volumes written and read from cache is higher, also the JDK is downloaded with each and every workflow run.

I don't get this πŸ€” Is it now downloaded or is it written into the cache? Or is it written to cache but additionally downloaded? 😱

Normally, it should write it to the cache but not downloading again (but fetched from cache). I'm not that familiar with the gradle/actions/setup-gradle action. However, I guess it should handle the jdk toolchain cache correctly πŸ€”