From e307fe3137dd07c8e150edfc32ffecebb992afc5 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 6 Jul 2015 15:24:48 +0200 Subject: [PATCH] Honor outputDirectory properly Previously, if the repackaged file was different from the main artifact of the build, the maven plugin wrongly considered that it should attach the file with a classifier. The outputDirectory is honored properly now, regardless of the fact a classifier is defined or not. Fixes gh-3177 --- .../src/it/jar-custom-dir/invoker.properties | 1 + .../src/it/jar-custom-dir/pom.xml | 58 +++++++++++++++++++ .../main/java/org/test/SampleApplication.java | 24 ++++++++ .../src/it/jar-custom-dir/verify.groovy | 14 +++++ .../boot/maven/RepackageMojo.java | 7 ++- 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/invoker.properties create mode 100644 spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/pom.xml create mode 100644 spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/src/main/java/org/test/SampleApplication.java create mode 100644 spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/verify.groovy diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/invoker.properties b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/invoker.properties new file mode 100644 index 00000000000..c0c3f7cc079 --- /dev/null +++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/invoker.properties @@ -0,0 +1 @@ +invoker.goals=clean install \ No newline at end of file diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/pom.xml b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/pom.xml new file mode 100644 index 00000000000..758874cea3d --- /dev/null +++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + org.springframework.boot.maven.it + jar-custom-dir + 0.0.1.BUILD-SNAPSHOT + + UTF-8 + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + repackage + + + ${project.build.directory}/foo + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + some.random.Main + + + Foo + + + + + + + + + org.springframework + spring-context + @spring.version@ + + + javax.servlet + javax.servlet-api + @servlet-api.version@ + provided + + + diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/src/main/java/org/test/SampleApplication.java b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/src/main/java/org/test/SampleApplication.java new file mode 100644 index 00000000000..fe6f4a1e00c --- /dev/null +++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/src/main/java/org/test/SampleApplication.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.test; + +public class SampleApplication { + + public static void main(String[] args) { + } + +} diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/verify.groovy b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/verify.groovy new file mode 100644 index 00000000000..9e69a7b94b1 --- /dev/null +++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-custom-dir/verify.groovy @@ -0,0 +1,14 @@ +import java.io.*; +import org.springframework.boot.maven.*; + +Verify.verifyJar( + new File( basedir, "target/foo/jar-custom-dir-0.0.1.BUILD-SNAPSHOT.jar" ), "some.random.Main" +); + +Verify.verifyJar( + new File( localRepositoryPath, "org/springframework/boot/maven/it/jar-custom-dir/0.0.1.BUILD-SNAPSHOT/jar-custom-dir-0.0.1.BUILD-SNAPSHOT.jar" ), "some.random.Main" +); + + + + diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java index 72161108410..a055abac6aa 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java @@ -199,13 +199,18 @@ public class RepackageMojo extends AbstractDependencyFilterMojo { catch (IOException ex) { throw new MojoExecutionException(ex.getMessage(), ex); } - if (!source.equals(target)) { + if (this.classifier != null) { getLog().info( "Attaching archive: " + target + ", with classifier: " + this.classifier); this.projectHelper.attachArtifact(this.project, this.project.getPackaging(), this.classifier, target); } + else if (!source.equals(target)) { + this.project.getArtifact().setFile(target); + getLog().info( + "Replacing main artifact " + source + " to " +target); + } } private File getTargetFile() {