Skip to content

Commit

Permalink
Add task to build the native image locally
Browse files Browse the repository at this point in the history
Use the task `nativeImageLocal`
  • Loading branch information
Noel Welsh committed Feb 14, 2020
1 parent 78c4591 commit 64be632
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,35 @@ libraryDependencies ++= Seq(

testFrameworks += new TestFramework("minitest.runner.Framework")

lazy val nativeImageLocal =
taskKey[File]("Build a standalone executable on this machine using GraalVM Native Image")

nativeImageLocal := {
import sbt.Keys.streams
val assemblyFatJar = assembly.value
val assemblyFatJarPath = assemblyFatJar.getAbsolutePath()
val outputName = "ping-server.local"
val outputPath = (baseDirectory.value / "out" / outputName).getAbsolutePath()

val cmd = s"""native-image
| -jar ${assemblyFatJarPath}
| ${outputPath}""".stripMargin.filter(_ != '\n')

val log = streams.value.log
log.info(s"Building local native image from ${assemblyFatJarPath}")
log.debug(cmd)
val result = (cmd.!(log))

if (result == 0) file(s"${outputPath}")
else {
log.error(s"Local native image command failed:\n ${cmd}")
throw new Exception("Local native image command failed")
}
}


lazy val nativeImage =
taskKey[File]("Build a standalone executable using GraalVM Native Image")
taskKey[File]("Build a standalone Linux executable using GraalVM Native Image")

nativeImage := {
import sbt.Keys.streams
Expand Down

0 comments on commit 64be632

Please sign in to comment.