Skip to content
Latchkey

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.

maven
[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]

Diagnose it: resolve the effective POM first

Maven merges parent POMs, profiles, and settings before it builds anything. The configuration causing your failure is frequently inherited or activated by a profile that is on locally and off in CI.

Terminal
# the fully resolved configuration Maven will actually use
mvn help:effective-pom | head -60

# which profiles are active here vs on your machine?
mvn help:active-profiles

# full error, offline-safe, no colour codes to confuse the log
mvn -B -e -X <goal> 2>&1 | tail -60

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.

pom.xml
<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.

pom.xml
<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.

Terminal
mvn -q clean package
# repackage runs as part of package, after the jar is built

How to prevent it

  • Set mainClass explicitly in multi-main projects.
  • Apply the Spring Boot plugin only to executable modules.
  • Build with package/verify in CI so the artifact exists before repackage.

Frequently asked questions

What causes Maven "Failed to execute goal spring-boot:repackage"?
There are 3 common causes: multiple or zero main classes, no jar produced before repackage, and the plugin is bound to the wrong phase or module. The plugin auto-detects the class with public static void main.
How do I fix Maven "Failed to execute goal spring-boot:repackage"?
There are 3 fixes depending on which cause you have: pin the main class, skip repackage on library modules, and run package so the jar exists. Work through them in order, since the first is the most common.
What does Maven "Failed to execute goal spring-boot:repackage" actually mean?
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 ...
How do I stop Maven "Failed to execute goal spring-boot:repackage" happening again?
Set mainClass explicitly in multi-main projects. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card