0

I am trying to build a native image of a Quarkus application with Gradle. I execute:

./gradlew build -Dquarkus.package.type=native -Dquarkus.native.container-build=true

It fails with the following error:

Execution failed for task ':my-service:quarkusBuild'.
> io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkus.deployment.pkg.steps.NativeImageBuildStep#build threw an exception: java.lang.RuntimeException: Failed to build native image
        at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.build(NativeImageBuildStep.java:223)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:820)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2442)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1476)
        at java.base/java.lang.Thread.run(Thread.java:829)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)
  Caused by: java.lang.RuntimeException: Image generation failed. Exit code was 137 which indicates an out of memory error. Consider increasing the Xmx value for native image generation by setting the "quarkus.native.native-image-xmx" property
        at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.imageGenerationFailed(NativeImageBuildStep.java:360)
        at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.build(NativeImageBuildStep.java:200)
        ... 11 more

As it is suggested in the stack trace, I try setting quarkus.native.native-image-xmx by adding the following instruction to the build command:

-Dquarkus.native.native-image-xmx=8g

Unfortunately it keeps failing. In the Activity Monitor, I see that java process doesn't use much memory while building (less then 1GB) which means, the property doesn't get applied.

Question: How to increase the size of Heap Memory while building a Quarkus native image with Gradle?

Sasha Shpota
  • 9,436
  • 14
  • 75
  • 148
  • I think if you try your build without the -Dquarkus.native.container-build=true it will assign the required memory, I think the issue is with the container, there is the "-Dquarkus.native.additional-build-args="-J-Dxxx." whch allows options to be passed directly to the vm https://www.graalvm.org/reference-manual/native-image/Options/ – Nigel Savage Aug 30 '21 at 12:25
  • Are you on Mac or Windows perhaps? – geoand Aug 30 '21 at 14:21
  • @geoand it's Mac – Sasha Shpota Aug 30 '21 at 14:32
  • @NigelSavage I cannot build without `-Dquarkus.native.container-build=true`. This would work only on Linux (as far as I understand). For me it would fail with: `java.lang.RuntimeException: The native binary produced by the build is not a Linux binary and therefore cannot be used in a Linux container image. Consider adding "quarkus.native.container-build=true" to your configuration` – Sasha Shpota Aug 30 '21 at 15:35
  • yes correct, what I was trying to convey is that possibly you need to try and pass parameters to the running container to tell it to use more memory – Nigel Savage Aug 30 '21 at 15:50
  • 1
    -Dquarkus.package.type=native -Dquarkus.native.container-build=true -Dquarkus.native.additional-build-args=-J-Xmx6g not sure about the syntax going off the -J in the doc https://www.graalvm.org/reference-manual/native-image/Options/ – Nigel Savage Aug 30 '21 at 16:00
  • You might need to increase the amount of memory that the VM Mac starts for Docker can use – geoand Aug 30 '21 at 19:45

0 Answers0