Capture the output from native-image build.

This commit is contained in:
Pavel Marek 2024-02-16 14:36:30 +01:00
parent c5cc2dc448
commit 743e167aa4

View File

@ -225,12 +225,23 @@ object NativeImage {
val process =
Process(cmd, None, "PATH" -> newPath)
if (process.! != 0) {
log.error("Native Image build failed.")
// All the output from native-image is redirected into a StringBuilder, and printed
// at the end of the build. This mitigates the problem when there are multiple sbt
// commands running in parallel and the output is intertwined.
val sb = new StringBuilder
val processLogger = ProcessLogger(str => {
sb.append(str + System.lineSeparator())
})
log.info(
s"Started building $artifactName native image. The output is captured."
)
val retCode = process.!(processLogger)
if (retCode != 0) {
log.error("Native Image build failed, with output: ")
println(sb.toString())
throw new RuntimeException("Native Image build failed")
}
log.info("Native Image build successful.")
log.info(s"$artifactName native image build successful.")
}
.dependsOn(Compile / compile)