Horje
Difference Between spring-boot:repackage and Maven package

Maven is a powerful build automation tool that also handles project management. The Spring Boot repackage is a plugin provided by Maven. This article explains the spring-boot:repackage goal and the Maven package phase. For this, you should have a good understanding of the Spring Framework and Maven build tool. In this article, we will learn spring-boot:repackage vs Maven package.

spring-boot:repackage

The spring-boot:repackage goal is provided by the Spring Boot Maven Plugin. This goal is specifically designed to support the creation of executable JAR or WAR files for Spring Boot applications. An executable JAR or WAR file created by spring-boot:repackage includes not only the compiled application code but also all the dependencies required to run the application.

Example:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Maven Package

The Maven package phase is part of the standard Maven build lifecycle. During this phase, Maven compiles the project’s source code, processes the resources, and packages the compiled code and resources into a distributable format, such as a JAR or WAR file. This packaged artifact is typically placed in the target directory of the project.

Example:

<build>
    <plugins>
        <!-- Other plugins may be configured here -->
    </plugins>
</build>

Prerequisites:

  • Maven Installation
  • JDK Installation
  • Maven Project Structure
  • pom.xml Configuration
  • Spring Boot Dependencies
  • Build Plugins
  • Internet Access
  • Project Compilation

Difference Between spring-boot:repackage and Maven package

Below is the difference table of spring-boot:repackage and Maven package.

Feature/Aspect

spring-boot:repackage

Maven package

Purpose

Creates an executable JAR or WAR with dependencies embedded.

Compiles the project code and packages it into a JAR or WAR file.

Plugin

Part of the Spring Boot Maven Plugin.

Part of the standard Maven build life cycle.

Execution Time

Typically run after package phase.

Runs as part of the standard Maven build life cycle, typically during the package phase.

Dependency Handling

Embeds all dependencies inside the executable JAR/WAR.

Does not embed dependencies; they remain separate.

Resulting Artifact

Fat JAR/WAR with all dependencies included.

Standard JAR/WAR without dependencies embedded.

Default Goal in Maven

No, must be explicitly called using mvn spring-boot:repackage.

Yes, part of the standard Maven life cycle.

Command Line Usage

mvn spring-boot:repackage

mvn package

Configuration Required

Requires Spring Boot Maven Plugin configuration in pom.xml.

No additional configuration needed beyond standard Maven setup.

Typical Use Case

To create standalone applications for easy deployment.

To compile and package code as part of the build process.

Executability

Produces an executable artifact that can be run directly with java -jar.

Produces a standard archive that requires dependencies to be provided separately at runtime.

Custom Manifest Entries

Adds entries required for Spring Boot applications to run correctly.

Standard manifest entries as defined by Maven or custom entries defined by the user.




Reffered: https://www.geeksforgeeks.org


Advance Java

Related
How to Configure Spring Boot TestRestTemplate? How to Configure Spring Boot TestRestTemplate?
How to Create and Setup Spring Boot Project in VSCode? How to Create and Setup Spring Boot Project in VSCode?
Eureka vs Consul: Service Registry Comparison Eureka vs Consul: Service Registry Comparison
Difference between Role and GrantedAuthority in Spring Security Difference between Role and GrantedAuthority in Spring Security
Maven Compiler Plugin Maven Compiler Plugin

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
16