Search code examples
spring-bootgraalvmgraalvm-native-image

Spring boot native build with multiple module


I'm now trying to build native executable by spring boot native build (GraalVM). Spring Doc.

But the command ./mvnw native:compile failed with

[ERROR] Failed to execute goal org.graalvm.buildtools:native-maven-plugin:0.9.22:compile (default-cli) on project myproject-parent: Execution of .jdks \graalvm-ce-17\bin\native-image.cmd @target\tmp\native-image-4847164668714484575.args returned non-zero result -> [Help 1]

Error: Please specify class (or /) containing the main entry point method. (see --help)

I think it's because maven try build native for the parent module. But the parent module has no main class, it shouldn't build native image.

My project is multi-module. it looks like

  • parent (inherit from spring-parent)
    • common
    • app-1
    • app-2

I want the native build only run for app-1 and app-2. How should I do?


Solution

  • Finally, I find the correct way.

    Spring doc says to use native:compile, but it will lead all module execute the goal. While we only want to run the goal on app modules.

    So instead of run native:compile, we use normal package. And attach the compile-no-fork goal to package phase. Only enable the plugin in app modules.