From 32453b27d3ceb6f7a2ca9ca2986c5d0f75563a81 Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Sat, 1 Feb 2014 14:57:18 +0000 Subject: [PATCH] Add mainClass option for Repackage task Add `mainClass` property option to the Repackage task. If the property is defined within a task, it works in the same way as if it defined within the springBoot{} 'ext' properties section. Option is valid only for that specific task where it is defined, and will override option defined in springBoot{} ext properties. Fixes gh-283 --- .../springframework/boot/gradle/task/Repackage.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 8423aa7ab6..b340274140 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 @@ -32,6 +32,7 @@ import org.springframework.boot.loader.tools.Repackager; * Repackage task. * * @author Phillip Webb + * @author Janne Valkealahti */ public class Repackage extends DefaultTask { @@ -41,6 +42,8 @@ public class Repackage extends DefaultTask { private Object withJarTask; + private String mainClass; + public void setCustomConfiguration(String customConfiguration) { this.customConfiguration = customConfiguration; } @@ -49,6 +52,10 @@ public class Repackage extends DefaultTask { this.withJarTask = withJarTask; } + public void setMainClass(String mainClass) { + this.mainClass = mainClass; + } + @TaskAction public void repackage() { Project project = getProject(); @@ -64,6 +71,7 @@ public class Repackage extends DefaultTask { else if (extension.getCustomConfiguration() != null) { libraries.setCustomConfigurationName(extension.getCustomConfiguration()); } + project.getTasks().withType(Jar.class, new Action() { @Override @@ -99,7 +107,9 @@ public class Repackage extends DefaultTask { } }; }; - repackager.setMainClass(extension.getMainClass()); + repackager + .setMainClass(Repackage.this.mainClass != null ? Repackage.this.mainClass + : extension.getMainClass()); if (extension.convertLayout() != null) { repackager.setLayout(extension.convertLayout()); }