{"record":{"id":"9787151414923117","repo":"spring-projects/spring-boot","slug":"source-file-is-not-available-make-sure-package","errorCode":null,"errorMessage":"Source file is not available, make sure 'package' runs as part of the same lifecycle","messagePattern":"Source file is not available, make sure 'package' runs as part of the same lifecycle","errorType":"exception","errorClass":"MojoExecutionException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java","lineNumber":191,"sourceCode":"\n\t@Override\n\tpublic void execute() throws MojoExecutionException, MojoFailureException {\n\t\tif (this.project.getPackaging().equals(\"pom\")) {\n\t\t\tgetLog().debug(\"repackage goal could not be applied to pom project.\");\n\t\t\treturn;\n\t\t}\n\t\tif (this.skip) {\n\t\t\tgetLog().debug(\"skipping repackaging as per configuration.\");\n\t\t\treturn;\n\t\t}\n\t\trepackage();\n\t}\n\n\tprivate void repackage() throws MojoExecutionException {\n\t\tArtifact source = getSourceArtifact(this.classifier);\n\t\tFile target = getTargetFile(this.finalName, this.classifier, this.outputDirectory);\n\t\tif (source.getFile() == null) {\n\t\t\tthrow new MojoExecutionException(\n\t\t\t\t\t\"Source file is not available, make sure 'package' runs as part of the same lifecycle\");\n\t\t}\n\t\tRepackager repackager = getRepackager(source.getFile());\n\t\tLibraries libraries = getLibraries(this.requiresUnpack);\n\t\ttry {\n\t\t\trepackager.repackage(target, libraries, parseOutputTimestamp());\n\t\t}\n\t\tcatch (IOException ex) {\n\t\t\tthrow new MojoExecutionException(ex.getMessage(), ex);\n\t\t}\n\t\tupdateArtifact(source, target, repackager.getBackupFile());\n\t}\n\n\tprivate @Nullable FileTime parseOutputTimestamp() throws MojoExecutionException {\n\t\ttry {\n\t\t\treturn new MavenBuildOutputTimestamp(this.outputTimestamp).toFileTime();\n\t\t}\n\t\tcatch (IllegalArgumentException ex) {","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java#L173-L209","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","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."],"exampleFix":"// before: mvn spring-boot:repackage\n// after:  mvn clean package spring-boot:repackage","handlingStrategy":"validation","validationCode":"// Pre-flight: source artifact must have a non-null file before repackage:\nArtifact source = getSourceArtifact(classifier);\nif (source.getFile() == null) {\n    throw new IllegalStateException(\"Run `mvn package` in the same lifecycle as repackage\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    // invoke repackage\n} catch (MojoExecutionException ex) {\n    if (ex.getMessage().startsWith(\"Source file is not available\")) {\n        // run `mvn package` first, then retry — do not retry unchanged\n    }\n    throw ex;\n}","preventionTips":["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."],"tags":["spring-boot","maven-plugin","repackage","packaging","lifecycle"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}