Maven "Failed to execute goal spring-boot:repackage" - Fix in CI
The Spring Boot Maven plugin tried to repackage your jar into an executable fat jar and failed - usually because it could not find a single main class, or there was no original jar to wrap.
What this error means
The build fails with Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:...:repackage, often with Unable to find a single main class from the following candidates or Source file ... must not be the same as the destination.
[ERROR] Failed to execute goal
org.springframework.boot:spring-boot-maven-plugin:3.3.2:repackage
(repackage) on project app: Execution repackage of goal ... failed:
Unable to find a single main class from the following candidates
[com.example.App, com.example.Tools] -> [Help 1]Common causes
Multiple or zero main classes
The plugin auto-detects the class with public static void main. With two candidates it cannot choose; with none it has nothing to launch.
No jar produced before repackage
A misconfigured packaging/jar step or a skipped package phase means there is no original artifact for repackage to wrap.
The plugin is bound to the wrong phase or module
Running repackage on a library module (one not meant to be executable) or before the jar is built triggers the failure.
How to fix it
Pin the main class
Tell the plugin exactly which class to launch when more than one main exists.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.example.App</mainClass>
</configuration>
</plugin>Skip repackage on library modules
Do not repackage modules that are not executable applications.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration><skip>true</skip></configuration>
</plugin>Run package so the jar exists
Repackage attaches to the package phase; build through it rather than running the goal alone.
mvn -q clean package
# repackage runs as part of package, after the jar is builtHow to prevent it
- Set
mainClassexplicitly in multi-main projects. - Apply the Spring Boot plugin only to executable modules.
- Build with
package/verifyin CI so the artifact exists before repackage.