|
1 | 1 | import kotlinx.validation.ApiValidationExtension |
2 | 2 | import okhttp3.buildsupport.testJavaVersion |
3 | 3 | import org.graalvm.buildtools.gradle.dsl.GraalVMExtension |
| 4 | +import org.graalvm.buildtools.gradle.tasks.BuildNativeImageTask |
4 | 5 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget |
5 | 6 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
6 | 7 | import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension |
| 8 | +import java.nio.file.Files |
7 | 9 |
|
8 | 10 | plugins { |
9 | 11 | kotlin("jvm") |
@@ -90,6 +92,46 @@ configure<GraalVMExtension> { |
90 | 92 | } else { |
91 | 93 | buildArgs("--no-fallback") |
92 | 94 | } |
| 95 | + |
| 96 | + javaLauncher.set( |
| 97 | + javaToolchains.launcherFor { |
| 98 | + languageVersion.set(JavaLanguageVersion.of(25)) |
| 99 | + vendor.set(JvmVendorSpec.GRAAL_VM) |
| 100 | + }, |
| 101 | + ) |
| 102 | + } |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +// https://github.com/gradle/gradle/issues/28583 |
| 107 | +tasks.named<BuildNativeImageTask>("nativeCompile") { |
| 108 | + // Gradle's "Copy" task cannot handle symbolic links, see https://github.com/gradle/gradle/issues/3982. That is why |
| 109 | + // links contained in the GraalVM distribution archive get broken during provisioning and are replaced by empty |
| 110 | + // files. Address this by recreating the links in the toolchain directory. |
| 111 | + val toolchainDir = |
| 112 | + options.get().javaLauncher.get().executablePath.asFile.parentFile.run { |
| 113 | + if (name == "bin") parentFile else this |
| 114 | + } |
| 115 | + |
| 116 | + val toolchainFiles = toolchainDir.walkTopDown().filter { it.isFile } |
| 117 | + val emptyFiles = toolchainFiles.filter { it.length() == 0L } |
| 118 | + |
| 119 | + // Find empty toolchain files that are named like other toolchain files and assume these should have been links. |
| 120 | + val links = |
| 121 | + toolchainFiles.mapNotNull { file -> |
| 122 | + emptyFiles.singleOrNull { it != file && it.name == file.name }?.let { |
| 123 | + file to it |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + // Fix up symbolic links. |
| 128 | + links.forEach { (target, link) -> |
| 129 | + logger.quiet("Fixing up '$link' to link to '$target'.") |
| 130 | + |
| 131 | + if (link.delete()) { |
| 132 | + Files.createSymbolicLink(link.toPath(), target.toPath()) |
| 133 | + } else { |
| 134 | + logger.warn("Unable to delete '$link'.") |
93 | 135 | } |
94 | 136 | } |
95 | 137 | } |
0 commit comments