From f83c6aa7c1568a208d9677338d49d4985ed15d72 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 16 Jun 2014 12:43:08 -0700 Subject: [PATCH] Grab main class from "run" task if it exists Fixes gh-1099 --- .../boot/gradle/repackage/RepackageTask.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/repackage/RepackageTask.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/repackage/RepackageTask.java index fe5b047c6b..38d79deea7 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/repackage/RepackageTask.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/repackage/RepackageTask.java @@ -114,13 +114,16 @@ public class RepackageTask extends DefaultTask { } private void setMainClass(Repackager repackager) { - repackager.setMainClass((String) getProject().property("mainClassName")); - if (this.extension.getMainClass() != null) { - repackager.setMainClass(this.extension.getMainClass()); - } + String mainClass = (String) getProject().property("mainClassName"); if (RepackageTask.this.mainClass != null) { - repackager.setMainClass(RepackageTask.this.mainClass); + mainClass = RepackageTask.this.mainClass; + } else if (this.extension.getMainClass() != null) { + mainClass = this.extension.getMainClass(); + } else if (getProject().getTasks().getByName("run").hasProperty("main")) { + mainClass = (String) getProject().getTasks().getByName("run").property("main"); } + getLogger().info("Setting mainClass: " + mainClass); + repackager.setMainClass(mainClass); } }