Auto discover GRAALVM_HOME
This commit is contained in:
parent
37dba17074
commit
8ad1e8d884
@ -1,10 +1,43 @@
|
||||
import org.gradle.jvm.toolchain.JavaToolchainService;
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
task("buildNative") {
|
||||
dependsOn("installShadowDist")
|
||||
|
||||
outputs.file("${buildDir}/native/scaffold")
|
||||
|
||||
doLast {
|
||||
val graalvmHome = System.getenv("GRAALVM_HOME") ?: error("GRAALVM_HOME is not set")
|
||||
val graalvmHome = project.extensions.findByType<JavaToolchainService>()?.launcherFor {
|
||||
languageVersion.set(JavaLanguageVersion.of(19))
|
||||
vendor.set(JvmVendorSpec.GRAAL_VM)
|
||||
}
|
||||
?.orNull
|
||||
?.executablePath?.asFile?.toPath()?.parent?.parent?.toString()
|
||||
?: System.getenv("GRAALVM_HOME")
|
||||
?: error("GRAALVM_HOME is not set")
|
||||
|
||||
val out = ByteArrayOutputStream()
|
||||
|
||||
exec {
|
||||
commandLine(
|
||||
"${graalvmHome}/bin/gu",
|
||||
"list",
|
||||
"-v",
|
||||
)
|
||||
standardOutput = out
|
||||
}
|
||||
|
||||
val installedComponents = out.toString().lines()
|
||||
.filter { it.startsWith("ID") }
|
||||
.map { it.substringAfter(':').trim() }
|
||||
|
||||
if ("native-image" !in installedComponents) {
|
||||
throw GradleException("GRAALVM: Missing js component")
|
||||
}
|
||||
|
||||
if ("js" !in installedComponents) {
|
||||
throw GradleException("GRAALVM: Missing js component")
|
||||
}
|
||||
|
||||
exec {
|
||||
commandLine(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user