Scott Palmer
09/17/2024, 1:06 AMdef launcher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(23)
}
tasks.named('anotherSampleTask') {
javaHome = launcher.map { it.metadata.installationPath }
}
I don't get something I can use as a path to Java Home.Vampire
09/17/2024, 7:51 AMThomas Broyer
09/17/2024, 10:01 AMScott Palmer
09/17/2024, 1:20 PMdef launcher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(23)
}
task jlink(type:Exec) {
def javaHome = launcher.map { it.metadata.installationPath }
commandLine "${javaHome}/bin/jlink", "--help"
}
This results in an error:
> A problem occured starting process 'command 'map(map(provider(?) (with side effect org.gradle.jvm.toolchain.internal.DefaultJavaToolchainService$$Lambda/0x000001929b9ef6b8@4a4d92c8)))/bin/jlink''Vampire
09/17/2024, 1:34 PMlauncher.map leaves you with a provider, you need to .get() it to get the actual valueVampire
09/17/2024, 1:37 PMVampire
09/17/2024, 1:37 PMScott Palmer
09/17/2024, 1:46 PMThomas Broyer
09/17/2024, 2:30 PMWARNING
The examples above use tasks with RegularFileProperty and DirectoryProperty properties which allow lazy configuration. Doing respectively launcher.get().executablePath, launcher.get().metadata.installationPath or compiler.get().executablePath instead will give you the full path for the given toolchain but note that this may realize (and provision) a toolchain eagerly.
Scott Palmer
09/17/2024, 4:01 PMget() in the warning is placed before the .metadata.installationPath so intuitively I thought the map { it.metadta.installationPath } was handling it.Vampire
09/17/2024, 4:03 PMmyProvider.map { it.foo }.get() == myProvider.get().fooVampire
09/17/2024, 4:03 PMVampire
09/17/2024, 4:04 PMget() at all and instead map and wire thingsScott Palmer
09/17/2024, 4:05 PMget()?Vampire
09/17/2024, 4:07 PMExec, but instead use exec { ... } at execution timeVampire
09/17/2024, 4:10 PMexecutable to something that does the get() in its toString() so that it at least is delayed as far as possibleVampire
09/17/2024, 4:10 PMexecutable hopefully