Skip to content

Commit

Permalink
native-image
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Jun 17, 2021
1 parent c0bbe1a commit 7014d4c
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import java.nio.file.*

plugins {
java
application
}

group = "org.glavo"
version = "0.3.0" + "-SNAPSHOT"
version = "0.3.0" //+ "-SNAPSHOT"

val mainName = "org.glavo.checksum.Main"

Expand All @@ -18,6 +20,8 @@ tasks.compileJava {
}

val executableJar by tasks.registering {
group = "build"

val outputDir = file("$buildDir/libs")
dependsOn(tasks.jar)

Expand All @@ -36,6 +40,7 @@ val executableJar by tasks.registering {
}

val nativeImageJar by tasks.registering(org.gradle.jvm.tasks.Jar::class) {
group = "build"
archiveClassifier.set("native-image")
from(sourceSets.main.get().output)
from("src/main/native-image")
Expand All @@ -49,5 +54,33 @@ tasks.withType(org.gradle.jvm.tasks.Jar::class) {
)
}

val buildNativeImage by tasks.registering {
group = "build"
dependsOn(nativeImageJar)

doLast {
val home = System.getenv("GRAALVM_HOME")
if (home == null) {
System.err.println("Missing GRAALVM_HOME")
} else {
val binPath = Paths.get(home).resolve("bin")

val ni = binPath.resolve("native-image.cmd").let {
if (Files.exists(it)) it else binPath.resolve("native-image")
}.toAbsolutePath().toString()


exec {
workingDir(file("$buildDir/libs"))
commandLine(
ni,
"-jar",
nativeImageJar.get().archiveFile.get().asFile
)
}
}
}
}

tasks.build.get().dependsOn(executableJar)
tasks.build.get().dependsOn(nativeImageJar)

0 comments on commit 7014d4c

Please sign in to comment.