Skip to content

Commit

Permalink
Gradle: Use GraalVM's native build tools plugin
Browse files Browse the repository at this point in the history
The advantage of GraalVM's native build tools plugin [1] over Palantir's
plugin is that reflection metadata is automatically downloaded and
Gradle's native toolchain mechanism [2] is used (via the Foojay Toolchains
Plugin [3]) to bootstrap GraalVM. By default, it uses the latest GraalVM
release for the language version of the JVM that runs the Gradle build.

[1]: https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html
[2]: https://docs.gradle.org/current/userguide/toolchains.html
[3]: https://github.com/gradle/foojay-toolchains

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
  • Loading branch information
sschuberth committed Jan 10, 2023
1 parent 2ebe377 commit 1d0e6a8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 622 deletions.
34 changes: 8 additions & 26 deletions cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ plugins {
application

// Apply third-party plugins.
alias(libs.plugins.graal)
alias(libs.plugins.graalVmNativeImage)
alias(libs.plugins.shadow)
}

Expand All @@ -36,32 +36,14 @@ application {
mainClass.set("org.ossreviewtoolkit.cli.OrtMainKt")
}

graal {
graalVersion(libs.versions.graal.get())
javaVersion("17")

// Build a standalone native executable or report a failure.
option("--no-fallback")

// Work-around for:
// "WARNING: Unknown module: org.graalvm.nativeimage.llvm specified to --add-exports"
option("-J--add-modules")
option("-JALL-SYSTEM")

// Work-around for:
// "Error: Classes that should be initialized at run time got initialized during image building"
option("--initialize-at-build-time=org.jruby.util.RubyFileTypeDetector")

// Work-around for:
// "Unsupported method java.lang.invoke.MethodHandleNatives.setCallSiteTargetNormal() is reachable"
option("--report-unsupported-elements-at-runtime")

// Work-around for:
// "Error: Non-reducible loop requires too much duplication"
option("-H:MaxDuplicationFactor=3.0")
graalvmNative {
metadataRepository {
enabled.set(true)
}
}

mainClass("org.ossreviewtoolkit.cli.OrtMainKt")
outputName("ort")
tasks.withType<Copy>().configureEach {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

tasks.withType<ShadowJar>().configureEach {
Expand Down
296 changes: 0 additions & 296 deletions cli/src/main/resources/META-INF/native-image/reflect-config.json

This file was deleted.

8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
detektPlugin = "1.22.0"
dokkaPlugin = "1.7.20"
downloadPlugin = "5.3.0"
graalPlugin = "0.12.0"
foojayResolverConventionPlugin = "0.4.0"
graalVmNativeImagePlugin = "0.9.19"
graphQlPlugin = "6.3.3"
ideaExtPlugin = "1.1.7"
kotlinPlugin = "1.8.0"
Expand All @@ -22,8 +23,6 @@ diskLruCache = "2.0.2"
exposed = "0.41.1"
flexmark = "0.64.0"
freemarker = "2.3.31"
# @keep this version which is only being used via get().
graal = "22.2.0"
greenmail = "1.6.12"
hikari = "5.0.1"
hoplite = "2.7.0"
Expand Down Expand Up @@ -66,7 +65,8 @@ xz = "1.9"
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detektPlugin" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokkaPlugin" }
download = { id = "de.undercouch.download", version.ref = "downloadPlugin" }
graal = { id = "com.palantir.graal", version.ref = "graalPlugin" }
foojayResolverConvention = { id = "org.gradle.toolchains.foojay-resolver-convention", version.ref = "foojayResolverConventionPlugin" }
graalVmNativeImage = { id = "org.graalvm.buildtools.native", version.ref = "graalVmNativeImagePlugin" }
graphQl = { id = "com.expediagroup.graphql", version.ref = "graphQlPlugin" }
ideaExt = { id = "org.jetbrains.gradle.plugin.idea-ext", version.ref = "ideaExtPlugin" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlinPlugin" }
Expand Down

0 comments on commit 1d0e6a8

Please sign in to comment.