spring-projects/spring-boot · error · MojoExecutionException
Source file is not available, make sure 'package' runs as…
Error message
Source file is not available, make sure 'package' runs as part of the same lifecycle
What it means
MojoExecutionException thrown by RepackageMojo.repackage when the resolved source artifact's File is null — i.e., no packaged jar/war exists to repackage. The plugin explicitly warns that package must run in the same lifecycle because a forked package goal would leave the artifact file unset at this point.
Solutions
- Bind or run repackaging with package: `mvn package spring-boot:repackage` (or rely on the default package-phase binding).
- Ensure packaging is jar/war (not pom) so an artifact is produced.
- If you use a forked jar-plugin execution, restructure so package runs in the same lifecycle as repackage.
- Verify <classifier> resolves to an attached artifact that actually has a file.
Example fix
// before: mvn spring-boot:repackage // after: mvn clean package spring-boot:repackage
Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight: source artifact must have a non-null file before repackage:
Artifact source = getSourceArtifact(classifier);
if (source.getFile() == null) {
throw new IllegalStateException("Run `mvn package` in the same lifecycle as repackage");
} Try / catch
try {
// invoke repackage
} catch (MojoExecutionException ex) {
if (ex.getMessage().startsWith("Source file is not available")) {
// run `mvn package` first, then retry — do not retry unchanged
}
throw ex;
} Prevention
- Always invoke `mvn package spring-boot:repackage` (or bind to the package phase).
- Ensure packaging is jar/war, not pom.
- Don't run repackage in a forked lifecycle that leaves the artifact file null.
When it happens
Trigger: Calling spring-boot:repackage directly/before package; binding repackage to a phase where the project artifact hasn't been produced; classifier resolves to an artifact whose file is null (typical when package ran in a forked lifecycle).
Common situations: Running `mvn spring-boot:repackage` alone; repackaging before the package phase; using forked execution of `maven-jar-plugin` so the artifact isn't attached yet; classifier misconfiguration; project never produces an artifact (e.g., pom packaging).
Related errors
- A jar or war file is required for building image
- Error packaging archive for image
- Invalid value for parameter 'outputTimestamp'
- Process terminated with exit code
- Can't parse ' ' to instant
AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11).
Data as JSON: /api/errors/9787151414923117.
Report an issue: GitHub.
Appendix: 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 270dfe353f)