{"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/5b2dbdbb8be64415eb6552f81ff7c449c8d251e6/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java#L173-L209","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nmvn spring-boot:repackage\n// after\nmvn package spring-boot:repackage","handlingStrategy":"validation","validationCode":"// Confirm the source artifact file exists before repackage\nimport org.apache.maven.artifact.Artifact;\n\nvoid ensureSourceFile(Artifact source) {\n    if (source.getFile() == null) {\n        throw new IllegalStateException(\"Run `mvn package` in the same lifecycle before repackage\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["maven","spring-boot","repackage","lifecycle","configuration"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}