Skip to content

Commit daa966c

Browse files
committed
Repackager: pluggable layouts. Support overriding launcher class.
Repackager: pluggable layouts. Support overriding launcher class.
1 parent 559a929 commit daa966c

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ import org.springframework.boot.loader.tools.Layouts
3838
*/
3939
public class SpringBootPluginExtension {
4040

41-
/**
41+
/**
42+
* Launcher class, replaces the default specified by layout. Optional.
43+
*/
44+
String launcherClass;
45+
46+
/**
4247
* The main class that should be run. Instead of setting this explicitly you can use the
4348
* 'mainClassName' of the project or the 'main' of the 'run' task. If not specified the
4449
* value from the MANIFEST will be used, or if no manifest entry is the archive will be

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ private void repackage(File file) {
166166
}
167167
Repackager repackager = new LoggingRepackager(file);
168168
setMainClass(repackager);
169+
repackager.setLauncherClass(this.extension.getLauncherClass());
169170
repackager.setLayout(this.extension.convertLayout());
170171
repackager.setBackupSource(this.extension.isBackupSource());
171172
try {

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
@@ -99,6 +99,12 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
9999
@Parameter
100100
private String classifier;
101101

102+
/**
103+
* Name of the launcher class; overrides the one specified by layout.
104+
*/
105+
@Parameter
106+
private String launcherClass;
107+
102108
/**
103109
* The name of the main class. If not specified the first compiled class found that
104110
* contains a 'main' method will be used.
@@ -155,6 +161,7 @@ protected String findMainMethod(JarFile source) throws IOException {
155161
}
156162
};
157163
repackager.setMainClass(this.mainClass);
164+
repackager.setLauncherClass(this.launcherClass);
158165

159166
getLog().info("Layout: " + this.layout);
160167
repackager.setLayout(Layouts.resolve(this.layout));

0 commit comments

Comments
 (0)