目标org.springframework.boot的执行默认值:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed:Source必须引用现有文件
我想使用maven-jar-plugin来构建diff分类器jar,比如:
mvn deploy:部署-p debug,classifier-demo-0.0.1-debug.jar
mvn deploy:部署-p test,classifier-demo-0.0.1-test.jar。
但失败了:
Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: Source must refer to an existing file
pom.xml:
4.0.0 org.springframework.boot spring-boot-starter-parent 1.2.3.RELEASE org.lenic classifier-demo 0.0.1 1.7 local-repo file://D:\repo test test debug true debug org.springframework.boot spring-boot-maven-plugin org.apache.maven.plugins maven-jar-plugin ${classifier}
目标:重新包装重新包装尝试重新包装原始工件,即projectName.jar。 这是maven的默认包阶段的结果,即mvn包命令输出。
当Repackage目标执行时,它会尝试查找projectName.jar。
当你运行mvn spring-boot:package时,projectName.jar不在那里。 为什么它会给出错误Source必须引用现有文件
解决方案:运行命令mvn clean package spring-boot:repackage
我想这就是原因:
this.project.getArtifact().getFile()
弹簧引导Maven的插件的\ src \主\ java的\组织\ springframework的\启动\行家\ RepackageMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { // ...... File source = this.project.getArtifact().getFile(); File target = getTargetFile(); Repackager repackager = new Repackager(source) { @Override protected String findMainMethod(JarFile source) throws IOException { long startTime = System.currentTimeMillis(); try { return super.findMainMethod(source); } finally { long duration = System.currentTimeMillis() - startTime; if (duration > FIND_WARNING_TIMEOUT) { getLog().warn( "Searching for the main-class is taking some time, " + "consider using the mainClass configuration " + "parameter"); } } } }; // ...... }
实际上,如果你设置Spring Boot Maven插件,你已经将spring-boot:repackage包含在包中。 所以只需“mvn clean package”就够了,我们不需要“mvn package spring-boot:repackage”。