Skip to content

Commit

Permalink
Pass arguments to native-image via argfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Akirathan committed Feb 19, 2024
1 parent 6a9fff2 commit ba0a69d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions project/NativeImage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ object NativeImage {
"ch.qos.logback"
)

val NATIVE_IMAGE_ARG_FILE = "native-image-args.txt"

/** Creates a task that builds a native image for the current project.
*
* This task must be setup in such a way that the assembly JAR is built
Expand Down Expand Up @@ -193,9 +195,7 @@ object NativeImage {

val verboseOpt = if (verbose) Seq("--verbose") else Seq()

var cmd: Seq[String] =
Seq(nativeImagePath) ++
verboseOpt ++
var args: Seq[String] =
Seq("-cp", cpStr) ++
quickBuildOption ++
debugParameters ++ staticParameters ++ configs ++
Expand All @@ -208,18 +208,27 @@ object NativeImage {
additionalOptions ++
Seq("-o", artifactName)

cmd = mainClass match {
args = mainClass match {
case Some(main) =>
cmd ++
args ++
Seq(main)
case None =>
cmd ++
args ++
Seq("-jar", pathToJAR.toString)
}

val targetDir = (Compile / target).value
val argFile = targetDir.toPath.resolve(NATIVE_IMAGE_ARG_FILE)
IO.writeLines(argFile.toFile, args, append = false)

val pathParts = pathExts ++ Option(System.getenv("PATH")).toSeq
val newPath = pathParts.mkString(File.pathSeparator)

val cmd =
Seq(nativeImagePath) ++
verboseOpt ++
Seq("@" + argFile.toAbsolutePath.toString)

log.debug(s"""PATH="$newPath" ${cmd.mkString(" ")}""")

val process =
Expand Down

0 comments on commit ba0a69d

Please sign in to comment.