-
Notifications
You must be signed in to change notification settings - Fork 275
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
Add Gradle toolchain support #262
base: main
Are you sure you want to change the base?
Conversation
In my opinion, it’s important that the Java version/vendor can be changed in a single place. For example, I often use this to reproduce a failed CI build. |
Any suggestion/recommendation how to do that? |
Perhaps you could add |
ad2fe32
to
fbc4556
Compare
How about renaming I think the project property is only useful for command-line invocations, so it could be a system property. Do your changes guarantee that source/targetCompatibility remains fixed at 11 (or soon 17) regardless of which JDK version is selected? |
Yes, that is the case 👍
Are you sure we wannt go with
We could do this, but not as a |
I think
System property would be a small improvement because setting the project property in a build script will likely not work correctly. |
d358b24
to
8bd04e2
Compare
This comment was marked as resolved.
This comment was marked as resolved.
8e59b6f
to
c240736
Compare
Seems we run into a few other Gradle 7x toolchain issues 🙈 Lets wait for #245 |
55897f7
to
c721eda
Compare
Hey @bioball and/or @stackoverflow I might need your help here:
If this is the case, then my changes are correct.
I tried various things, but non of the results look like it should (or maybe? 🤷 ) So what I'm doing wrong? |
c721eda
to
5b2e95b
Compare
Hey @StefMa! Just getting around to looking at this. To fix the patch file: you can apply the patch on a file-by-file basis using In this case, I think what you need to do is:
|
The CI tests are failing on task Cause:
I tried running this locally in docker using
So, it seems like Gradle toolchains might affect built-in Java compile and run tasks, but for some reason it doesn't affect Seems like we can fix it by adding this to tasks.withType<JavaExec>().configureEach {
javaLauncher.set(javaToolchains.launcherFor(java.toolchain))
} |
} | ||
} | ||
} | ||
jvmToolchain(11) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would it make sense to configure the global toolchain here as well, for consistency, via the java { toolchain { } }
block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build.gradle.kts
is only responsible for the code within buildSrc
, right?
Since we are using Kotlin only here, why should we set the java.toolchain {}
? 🤔
Or what do you mean by that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are correct that this build script is responsible for buildSrc
.
In Gradle, the java
plugin is always applied to JVM-based projects, even if the project uses some other language as the core of its implementation. Therefore, for consistency, it is considered idiomatic to use the java
plugin methods to configure something first, and use language-specific methods to adjust the configuration, if necessary.
In the toolchain case, it is specified explicitly in Kotlin docs (see here) that the toolchain version in the java
block will be used by Kotlin compilation tasks, therefore, it would be conventional to use the java
block to set it up.
(BTW, it's curious that the docs state that setting the toolchain in the kotlin
extension will also configure it for JavaCompile
tasks; this is another reason to set it in the java
block, since it is the built-in way to configure the toolchain, and their effects would be similar anyway)
Thanks for you comment here @bioball !
Setting the same code in the
I tried different things but run out of ideas here 🙈 |
kotlin.jvmToolchain { | ||
languageVersion.set(jvmToolchainVersion) | ||
vendor.set(jvmToolchainVendor) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be necessary because this plugin applies pklJavaLibrary
, and the latter already applies the toolchain in the java {}
block.
fixes #184
With that we can get rid of the java 11 check and the information around it.
Also, we can "on the fly" update the jdk version the project will build on.
We only need "a" java version installed to start Gradle.
As discussed in the ticket, I also had to update Gradle to version 7.6 which (seems) brings flaky tests.
But we can't use toolchains before that version.
So maybe this PR wil hang here until this is fixed 🙃
Questions / Todos
I guess this is not going to work anymore (or has to be adjusted)
👉 https://github.com/apple/pkl/blob/2499e2c4937fc228e49e94e41fdaac065c203168/.circleci/config.pkl#L98C7-L107
I guess this is not going to work anymore (or has to be adjusted)
👉
pkl/patches/graalVm23.patch
Lines 25 to 30 in 2499e2c
Let me know if there is more like these 🙃