From a37e9832962c4b64f53defa058b0986ea0a42c22 Mon Sep 17 00:00:00 2001 From: Lugi Cardito Date: Tue, 9 Jun 2015 18:46:28 +0100 Subject: [PATCH] Create output directory if necessary If the `repackage` goal defines an output directory that does not exist, the maven plugin now creates it. Closes gh-3136 --- .../src/it/jar-create-dir/pom.xml | 59 +++++++++++++++++++ .../main/java/org/test/SampleApplication.java | 24 ++++++++ .../src/it/jar-create-dir/verify.groovy | 7 +++ .../boot/maven/RepackageMojo.java | 5 ++ 4 files changed, 95 insertions(+) create mode 100644 spring-boot-tools/spring-boot-maven-plugin/src/it/jar-create-dir/pom.xml create mode 100644 spring-boot-tools/spring-boot-maven-plugin/src/it/jar-create-dir/src/main/java/org/test/SampleApplication.java create mode 100644 spring-boot-tools/spring-boot-maven-plugin/src/it/jar-create-dir/verify.groovy diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-create-dir/pom.xml b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-create-dir/pom.xml new file mode 100644 index 00000000000..9538ec1f661 --- /dev/null +++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-create-dir/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + org.springframework.boot.maven.it + jar-create-dir + 0.0.1.BUILD-SNAPSHOT + + UTF-8 + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + repackage + + + ${project.build.directory}/foo + 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-create-dir/src/main/java/org/test/SampleApplication.java b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-create-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-create-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-create-dir/verify.groovy b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-create-dir/verify.groovy new file mode 100644 index 00000000000..7538fcfa239 --- /dev/null +++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-create-dir/verify.groovy @@ -0,0 +1,7 @@ +import java.io.*; +import org.springframework.boot.maven.*; + +Verify.verifyJar( + new File( basedir, "target/foo/jar-create-dir-0.0.1.BUILD-SNAPSHOT-foo.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 6b8a7bee152..e06e9b51d8b 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 @@ -186,6 +186,11 @@ public class RepackageMojo extends AbstractDependencyFilterMojo { if (classifier.length() > 0 && !classifier.startsWith("-")) { classifier = "-" + classifier; } + + if (!this.outputDirectory.exists()) { + this.outputDirectory.mkdirs(); + } + return new File(this.outputDirectory, this.finalName + classifier + "." + this.project.getArtifact().getArtifactHandler().getExtension()); }