Rafael Scott
06/03/2024, 11:34 AMnative-image
is unable to find my lib specified in my build.gradle.kts
file:
plugins {
kotlin("jvm") version "1.9.23"
}
group = "com.example"
version = "1.0-SNAPSHOT"
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = "com.example.SampleCli"
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("com.github.ajalt.clikt:clikt:4.3.0")
testImplementation(kotlin("test"))
}
tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(21)
}
task<Exec>("buildNativeImage") {
description = "Build native image using GraalVM"
dependsOn(tasks.getByName("build"))
workingDir(buildDir)
commandLine(
"native-image",
"-cp", getClasspath(),
"-H:+ReportExceptionStackTraces",
"-H:+AddAllCharsets",
// "--report-unsupported-elements-at-runtime",
// "--allow-incomplete-classpath",
"--no-server",
"--no-fallback",
"--enable-http",
"--enable-https",
"com.example.SampleCli",
"com.example"
)
}
Whereas I can build it using ./gradlew build
, GraalVM can't find my dependency when I try to run the task:
/gradlew buildNativeImage
or even when I try to run native-image
manually:
native-image -jar build/libs/SampleCli-1.0-SNAPSHOT.jar cli
Error (same error for both actions):
========================================================================================================================
GraalVM Native Image: Generating 'cli' (executable)...
========================================================================================================================
[1/8] Initializing... (0.0s @ 0.15GB)
The build process encountered an unexpected error:
> java.lang.NoClassDefFoundError: com/github/ajalt/clikt/core/CliktCommand
Please inspect the generated error report at:
/Users/user1/SampleProject/svm_err_b_20240603T04124.720_pid14052.md
If you are unable to resolve this problem, please file an issue with the error report at:
<https://graalvm.org/support>
Am able to run this main class fine via IntelliJ...CLOVIS
06/03/2024, 12:12 PMbuild/libs/SampleCli-1.0-SNAPSHOT.jar
only contains your code, not dependencies.
Have you checked if there is a GraalVM plugin that exists?Vampire
06/03/2024, 12:17 PM-cp ...
argument to the native-image
call, so that also the dependencies are built into the resultVampire
06/03/2024, 12:18 PM