diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPlugin.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPlugin.java index aec35a5a5c..5a015d8f98 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPlugin.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPlugin.java @@ -31,7 +31,7 @@ import org.springframework.boot.gradle.task.RunJar; */ public class SpringBootPlugin implements Plugin { - private static final String REPACKAGE_TASK_NAME = "repackage"; + private static final String REPACKAGE_TASK_NAME = "bootRepackage"; private static final String RUN_JAR_TASK_NAME = "runJar"; @@ -40,6 +40,11 @@ public class SpringBootPlugin implements Plugin { project.getPlugins().apply(BasePlugin.class); project.getPlugins().apply(JavaPlugin.class); project.getExtensions().create("springBoot", SpringBootPluginExtension.class); + + // register BootRepackage so that we can use + // task foo(type: BootRepackage) {} + project.getExtensions().getExtraProperties() + .set("BootRepackage", Repackage.class); Repackage packageTask = addRepackageTask(project); ensureTaskRunsOnAssembly(project, packageTask); addRunJarTask(project); diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPluginExtension.groovy b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPluginExtension.groovy index e031574119..20b05fe2f8 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPluginExtension.groovy +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPluginExtension.groovy @@ -59,6 +59,11 @@ public class SpringBootPluginExtension { */ String providedConfiguration + /** + * The name of the custom configuration to use. + */ + String customConfiguration + /** * If the original source archive should be backed-up before being repackaged. */ diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/ProjectLibraries.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/ProjectLibraries.java index a2aac00d8c..4b9fcada10 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/ProjectLibraries.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/ProjectLibraries.java @@ -1,4 +1,3 @@ - package org.springframework.boot.gradle.task; import java.io.File; @@ -21,6 +20,7 @@ class ProjectLibraries implements Libraries { private final Project project; private String providedConfigurationName = "providedRuntime"; + private String customConfigurationName = null; /** * Create a new {@link ProjectLibraries} instance of the specified {@link Project}. @@ -40,24 +40,39 @@ class ProjectLibraries implements Libraries { this.providedConfigurationName = providedConfigurationName; } + public void setCustomConfigurationName(String customConfigurationName) { + this.customConfigurationName = customConfigurationName; + } + @Override public void doWithLibraries(LibraryCallback callback) throws IOException { - FileCollection compile = this.project.getConfigurations().getByName("compile"); + FileCollection custom = this.customConfigurationName != null ? this.project + .getConfigurations().findByName(this.customConfigurationName) : null; - FileCollection runtime = this.project.getConfigurations().getByName("runtime"); - runtime = runtime.minus(compile); + if (custom != null) { + libraries(LibraryScope.CUSTOM, custom, callback); + } + else { + FileCollection compile = this.project.getConfigurations() + .getByName("compile"); + + FileCollection runtime = this.project.getConfigurations() + .getByName("runtime"); + runtime = runtime.minus(compile); + + FileCollection provided = this.project.getConfigurations().findByName( + this.providedConfigurationName); + if (provided != null) { + compile = compile.minus(provided); + runtime = runtime.minus(provided); + } - FileCollection provided = this.project.getConfigurations().findByName( - this.providedConfigurationName); - if (provided != null) { - compile = compile.minus(provided); - runtime = runtime.minus(provided); + libraries(LibraryScope.COMPILE, compile, callback); + libraries(LibraryScope.RUNTIME, runtime, callback); + libraries(LibraryScope.PROVIDED, provided, callback); } - libraries(LibraryScope.COMPILE, compile, callback); - libraries(LibraryScope.RUNTIME, runtime, callback); - libraries(LibraryScope.PROVIDED, provided, callback); } private void libraries(LibraryScope scope, FileCollection files, diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/Repackage.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/Repackage.java index afb20574fc..a1da166a0c 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/Repackage.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/Repackage.java @@ -34,6 +34,18 @@ import org.springframework.boot.loader.tools.Repackager; */ public class Repackage extends DefaultTask { + private String customConfiguration; + + private Object withJarTask; + + public void setCustomConfiguration(String customConfiguration) { + this.customConfiguration = customConfiguration; + } + + public void setWithJarTask(Object withJarTask) { + this.withJarTask = withJarTask; + } + @TaskAction public void repackage() { Project project = getProject(); @@ -43,10 +55,23 @@ public class Repackage extends DefaultTask { if (extension.getProvidedConfiguration() != null) { libraries.setProvidedConfigurationName(extension.getProvidedConfiguration()); } + if (this.customConfiguration != null) { + libraries.setCustomConfigurationName(this.customConfiguration); + } + else if (extension.getCustomConfiguration() != null) { + libraries.setCustomConfigurationName(extension.getCustomConfiguration()); + } project.getTasks().withType(Jar.class, new Action() { @Override public void execute(Jar archive) { + // if withJarTask is set, compare tasks + // and bail out if we didn't match + if (Repackage.this.withJarTask != null + && !archive.equals(Repackage.this.withJarTask)) { + return; + } + if ("".equals(archive.getClassifier())) { File file = archive.getArchivePath(); if (file.exists()) { diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LibraryScope.java b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LibraryScope.java index 510d20c497..5892acca23 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LibraryScope.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LibraryScope.java @@ -55,4 +55,14 @@ public interface LibraryScope { }; }; + /** + * Marker for custom scope when custom configuration is used. + */ + public static final LibraryScope CUSTOM = new LibraryScope() { + @Override + public String toString() { + return "custom"; + }; + }; + }