'Spring Boot build image failure for native image

Using spring boot 2.6.2, with java17, trying to create native image but it fails with below error.

I am building it on windows 11 machine with docker desktop installed

mvnw spring-boot:build-image

[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/com.example.shoppinglist.ShoppinglistApplication:204]    classlist:  10,121.42 ms,  1.20 GB
[INFO]     [creator]     20:58:34.611 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4j2LoggerProvider
[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/com.example.shoppinglist.ShoppinglistApplication:204]        (cap):     773.97 ms,  1.70 GB
[INFO]     [creator]     Warning: Could not register org.springframework.boot.actuate.web.mappings.reactive.RequestMappingConditionsDescription: allDeclaredConstructors for reflection. Reason: java.lang.NoClassDefFoundError: org/springframework/web/reactive/result/method/RequestMappingInfo.
[INFO]     [creator]     Warning: Could not register org.springframework.boot.actuate.web.mappings.reactive.RequestMappingConditionsDescription$MediaTypeExpressionDescription: allDeclaredConstructors for reflection. Reason: java.lang.NoClassDefFoundError: org/springframework/web/reactive/result/condition/MediaTypeExpression.
[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/com.example.shoppinglist.ShoppinglistApplication:204]        setup:   3,523.59cation:204]        setup:   3,523.59 ms,  1.70 GB
[INFO]     [creator]     Warning: Could not register complete reflection metadata for org.springframework.boot.actuate.web.mappings.reactive.RequestMappingConditionsDescription. Reason(s): java.lang.NoClassDefFoundError: org/springframework/web/reactive/result/method/RequestMappingInfo
[INFO]     [creator]     Warning: Could not register complete reflection metadata for org.springframework.boot.actuate.web.mappings.reactive.RequestMappingConditionsDescription$MediaTypeExpressionDescription. Reason(s): java.lang.NoClassDefFoundError: org/springframework/web/reactive/result/condition/MediaTypeExpression
[INFO]     [creator]     Error: Image build request failed with exit status 137
[INFO]     [creator]     unable to invoke layer creator
[INFO]     [creator]     unable to contribute native-image layer
[INFO]     [creator]     error running build
[INFO]     [creator]     exit status 137
[INFO]     [creator]     ERROR: failed to build: exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  04:47 min
[INFO] Finished at: 2022-01-19T02:30:19+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.6.2:build-image (default-cli) on project shoppinglist: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.6.2:build-image failed: Builder lifecycle 'creator' failed with status code 145 -> [Help 1]
[ERROR]


Solution 1:[1]

Creating native images consumes a lot of memory. This message appears when the system runs out of memory.

In this official documentation you can find some tips and tricks related to this error:

https://docs.spring.io/spring-native/docs/0.11.1/reference/htmlsingle/#_out_of_memory_error_when_building_the_native_image

UPDATE

In the referenced documentation another SO answer is referenced with more trips&tricks: How to assign more memory to docker container

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1