Skip to content
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 support for Java Toolchains in Quarkus Gradle plugin #44392

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

joschi
Copy link
Contributor

@joschi joschi commented Nov 8, 2024

Add support for Toolchains for JVM projects to the Quarkus Gradle plugin.

The implementation tries to be close to the one used in the Gradle JavaExec task, assuming this is The Way™ since that isn't always quite clear in Gradle. 😓

Closes #20452

Copy link

quarkus-bot bot commented Nov 8, 2024

Thanks for your pull request!

Your pull request does not follow our editorial rules. Could you have a look?

  • title should preferably start with an uppercase character (if it makes sense!)
  • title should not start with chore/docs/feat/fix/refactor but be a proper sentence

This message is automatically generated by a bot.

@joschi joschi force-pushed the issue-20452-gradle-java-toolchain branch from 3673d23 to fb911c8 Compare November 8, 2024 18:54
@quarkus-bot quarkus-bot bot added area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/gradle Gradle labels Nov 8, 2024
@joschi joschi changed the title feat: support for Java Toolchains in Quarkus Gradle plugin Add support for Java Toolchains in Quarkus Gradle plugin Nov 8, 2024
@joschi joschi force-pushed the issue-20452-gradle-java-toolchain branch 3 times, most recently from c5184c5 to 369adff Compare November 19, 2024 07:50
@joschi
Copy link
Contributor Author

joschi commented Nov 19, 2024

@gsmet Maybe you could kindly ping the right people to review the PR? 😇

@gastaldi gastaldi requested a review from glefloch November 19, 2024 13:47
@gsmet
Copy link
Member

gsmet commented Nov 25, 2024

Yeah sorry, we are a bit short of reviewers/owners for the Gradle plugin unfortunately. Let's at least see if CI is happy :).

@gsmet
Copy link
Member

gsmet commented Nov 25, 2024

BTW, if you're willing to contribute in the Gradle area, we have some issues that need fixing and that would help a lot :).

This comment has been minimized.

@joschi joschi force-pushed the issue-20452-gradle-java-toolchain branch from ceb94c1 to f672ef4 Compare November 29, 2024 12:37
@@ -58,4 +64,13 @@ public static List<Dependency> listProjectBoms(Project project) {
return boms;
}

@Nullable
public static JavaToolchainSpec getExecutableOverrideToolchainSpec(ObjectFactory objectFactory) {
String customExecutable = objectFactory.newInstance(DefaultJavaExecSpec.class).getExecutable();
Copy link
Contributor

@asodja asodja Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just passing by:
JavaExec is doing that because for JavaExec you can set java as executable. For your task that doesn't make a lot of sense and objectFactory.newInstance(DefaultJavaExecSpec.class).getExecutable(); will always return null anyway. Also you are referencing internal type, it would be great if you could avoid that :)

I assume you want to achieve logic like:

if (quarkusTask has set toolchain) {
   use that
} else {
  use toolchains from JavaExtension
} 

You can achieve that with something like:

Provider<JavaLauncher> javaExtensionToolchainLauncher = getToolchainService().launcherFor(getJavaPluginExtension().getToolchain());
task.getJavaLauncher().convention(javaExtensionToolchainLauncher);

See also https://docs.gradle.org/current/userguide/toolchains.html#sec:plugins_toolchains

I hope that helps! 👋

@@ -60,14 +92,18 @@ WorkQueue workQueue(Map<String, String> configMap, List<Action<? super JavaForkO
}

return workerExecutor.processIsolation(processWorkerSpec -> configureProcessWorkerSpec(processWorkerSpec,
configMap, forkOptionsSupplier));
configMap, forkOptionsSupplier, getJavaLauncher().get()));
Copy link
Contributor

@asodja asodja Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling .get() will throw exeption if value is null. But launcher here will never be null, since it's not marked as @Optional. And if user sets it to null (they need to also unset convention on the property) then this task will fail already at validation.

What I am trying to say is: It seems in this case you don't need to check launcher != null later on, unless you mark getJavaLauncher() as @Optional @Nested, but then you also need to call .getOrNull() here. But I think it makes more sense that getJavaLauncher() is not allowed to be null and with that you can remove null check later on

Copy link

quarkus-bot bot commented Dec 20, 2024

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit f672ef4.

Failing Jobs

Status Name Step Failures Logs Raw logs Build scan
Initial JDK 17 Build Build Failures Logs Raw logs 🔍

You can consult the Develocity build scans.

Failures

⚙️ Initial JDK 17 Build #

- Failing: devtools/gradle/gradle-application-plugin 
! Skipped: integration-tests/gradle 

📦 devtools/gradle/gradle-application-plugin

Failed to execute goal net.revelc.code:impsort-maven-plugin:1.12.0:check (check-imports) on project io.quarkus.gradle.plugin: Imports are not sorted in /home/runner/work/quarkus/quarkus/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/GradleUtils.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/gradle Gradle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gradle plugin resp. quarkusBuild task does not honor toolchain definitions
3 participants