spring-projects/spring-boot · error · MojoExecutionException
Source file is not available, make sure 'package' runs as pa
Error message
Source file is not available, make sure 'package' runs as part of the same lifecycle
What it means
Thrown by RepackageMojo.repackage as a MojoExecutionException when getSourceArtifact(...).getFile() returns null — i.e. the artifact to be repackaged has no associated file on disk. spring-boot:repackage operates on the just-built artifact, so if the package phase did not run in the same lifecycle (or was skipped), the artifact file is null and repackaging cannot proceed. The message explicitly tells the user to run package in the same lifecycle.
Source
Thrown at build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java:191
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (this.project.getPackaging().equals("pom")) {
getLog().debug("repackage goal could not be applied to pom project.");
return;
}
if (this.skip) {
getLog().debug("skipping repackaging as per configuration.");
return;
}
repackage();
}
private void repackage() throws MojoExecutionException {
Artifact source = getSourceArtifact(this.classifier);
File target = getTargetFile(this.finalName, this.classifier, this.outputDirectory);
if (source.getFile() == null) {
throw new MojoExecutionException(
"Source file is not available, make sure 'package' runs as part of the same lifecycle");
}
Repackager repackager = getRepackager(source.getFile());
Libraries libraries = getLibraries(this.requiresUnpack);
try {
repackager.repackage(target, libraries, parseOutputTimestamp());
}
catch (IOException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
}
updateArtifact(source, target, repackager.getBackupFile());
}
private @Nullable FileTime parseOutputTimestamp() throws MojoExecutionException {
try {
return new MavenBuildOutputTimestamp(this.outputTimestamp).toFileTime();
}
catch (IllegalArgumentException ex) {View on GitHub (pinned to 5b2dbdbb8b)
Solutions
- Always run package and repackage together: `mvn package spring-boot:repackage`.
- Bind spring-boot:repackage to the package phase (its defaultPhase) — do not move it earlier.
- Do not disable the default jar/war packaging binding that produces the source artifact.
- If using a classifier, ensure the source artifact exists first (run package).
Example fix
// before mvn spring-boot:repackage // after mvn package spring-boot:repackage
Defensive patterns
Strategy: validation
Validate before calling
// Confirm the source artifact file exists before repackage
import org.apache.maven.artifact.Artifact;
void ensureSourceFile(Artifact source) {
if (source.getFile() == null) {
throw new IllegalStateException("Run `mvn package` in the same lifecycle before repackage");
}
} Prevention
- Always invoke `mvn package spring-boot:repackage`, never repackage alone.
- Keep spring-boot:repackage bound to the package phase or later.
- Do not disable the default jar/war binding that produces the source artifact.
When it happens
Trigger: Invoking spring-boot:repackage directly without package (e.g. mvn spring-boot:repackage); binding repackage to a phase before package; running only the repackage goal from a reactor where the module never packaged; a classifier pointing at an artifact that was never attached; combining repackage with skip of the default-jar binding.
Common situations: Running `mvn spring-boot:repackage` standalone; disabling maven-jar-plugin's default-jar execution; misconfiguring <executions> so repackage runs in process-classes; a multi-module build where the reactor only ran the repackage goal on a leaf module.
Related errors
- A jar or war file is required for building image
- Invalid value for parameter 'outputTimestamp'
- Failed to load layers configuration with name '%s': '%s' not
- Failed to process custom layers configuration {}
- Could not build classpath
AI-assisted analysis of spring-projects/spring-boot@5b2dbdbb8b (2026-08-04).
Data as JSON: /data/errors/9787151414923117.json.
Report an issue: GitHub.