Home > front end >  Confusion on Spring Boot Maven plugin goals
Confusion on Spring Boot Maven plugin goals

Time:01-25

I am working on Spring Boot 3 project and trying to build a native image using GraalVM native build tool. I have added the native image plugin (org.graalvm.buildtools:native-maven-plugin) in pom.xml. I am confused about which of the below two commands to use to build a native jar.

mvn -f ./pom.xml -Pnative package

or

mvn -f ./pom.xml -Pnative native:compile

Both are generating the jars in the target directory and adding the graalvm-reachabilty metadata. I want to know how these 2 goals differ and which one should be used to build a native jar.

CodePudding user response:

The difference between the two commands you provided is the goal that is being executed.

The first command, "mvn -f ./pom.xml -Pnative package", is executing the "package" goal of the Maven build process. This goal will compile and package your application into a JAR file, and any additional configuration specified in the pom.xml file, such as the GraalVM native-maven-plugin, will also be executed. This command will generate a jar file with all the dependencies included, this is the regular jar format that runs on JVM.

The second command, "mvn -f ./pom.xml -Pnative native:compile", is executing the "native:compile" goal of the GraalVM native-maven-plugin. This goal will take the JAR file generated by the "package" goal and use it to create a native image. The native image is a standalone executable that does not require the Java Virtual Machine (JVM) to run, it will have better performance than the regular jar.

  • Related