Skip to content

Commit eb5f381

Browse files
committed
plugins: support for overriding layout-provided launcher class
1 parent 7c6ee87 commit eb5f381

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPluginExtension.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public class SpringBootPluginExtension {
5959
}
6060
}
6161

62+
/**
63+
* Launcher class, replaces the default specified by layout. Optional.
64+
*/
65+
String launcherClass;
66+
6267
/**
6368
* The main class that should be run. Instead of setting this explicitly you can use the
6469
* 'mainClassName' of the project or the 'main' of the 'run' task. If not specified the

spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/repackage/RepackageTask.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ private void repackage(File file) {
165165
}
166166
Repackager repackager = new LoggingRepackager(file);
167167
setMainClass(repackager);
168+
setLauncherClass(repackager);
168169
if (this.extension.convertLayout() != null) {
169170
repackager.setLayout(this.extension.convertLayout());
170171
}
@@ -201,6 +202,12 @@ else if (getProject().getTasks().getByName("run").hasProperty("main")) {
201202
getLogger().info("Setting mainClass: " + mainClass);
202203
repackager.setMainClass(mainClass);
203204
}
205+
206+
private void setLauncherClass(Repackager repackager) {
207+
String launcherClass = extension.getLauncherClass();
208+
getLogger().info("Setting mainClass: " + launcherClass);
209+
repackager.setLauncherClass(launcherClass);
210+
}
204211
}
205212

206213
/**

spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class Repackager {
4242

4343
private static final byte[] ZIP_FILE_HEADER = new byte[] { 'P', 'K', 3, 4 };
4444

45+
private String launcherClass;
46+
4547
private String mainClass;
4648

4749
private boolean backupSource = true;
@@ -58,6 +60,10 @@ public Repackager(File source) {
5860
this.layout = Layouts.forFile(source);
5961
}
6062

63+
public void setLauncherClass(String launcherClass) {
64+
this.launcherClass = launcherClass;
65+
}
66+
6167
/**
6268
* Sets the main class that should be run. If not specified the value from the
6369
* MANIFEST will be used, or if no manifest entry is found the archive will be
@@ -229,7 +235,9 @@ private Manifest buildManifest(JarFile source) throws IOException {
229235
if (startClass == null) {
230236
startClass = findMainMethod(source);
231237
}
232-
String launcherClassName = this.layout.getLauncherClassName();
238+
String launcherClassName = (launcherClass != null)
239+
? launcherClass
240+
: layout.getLauncherClassName();
233241
if (launcherClassName != null) {
234242
manifest.getMainAttributes()
235243
.putValue(MAIN_CLASS_ATTRIBUTE, launcherClassName);

spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
100100
@Parameter
101101
private String classifier;
102102

103+
/**
104+
* Name of the launcher class; overrides the one specified by layout.
105+
*/
106+
@Parameter
107+
private String launcherClass;
108+
103109
/**
104110
* The name of the main class. If not specified the first compiled class found that
105111
* contains a 'main' method will be used.
@@ -156,6 +162,7 @@ protected String findMainMethod(JarFile source) throws IOException {
156162
}
157163
};
158164
repackager.setMainClass(this.mainClass);
165+
repackager.setLauncherClass(this.launcherClass);
159166
if (this.layout != null) {
160167
getLog().info("Layout: " + this.layout);
161168
repackager.setLayout(this.layout.layout());

0 commit comments

Comments
 (0)