Skip to content

Commit 3021de8

Browse files
committed
Repackager: pluggable layouts. Support overriding launcher class.
1 parent 31e6b55 commit 3021de8

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
@@ -41,7 +41,12 @@ import org.springframework.boot.loader.tools.Layouts
4141
*/
4242
public class SpringBootPluginExtension {
4343

44-
/**
44+
/**
45+
* Launcher class, replaces the default specified by layout. Optional.
46+
*/
47+
String launcherClass;
48+
49+
/**
4550
* The main class that should be run. Instead of setting this explicitly you can use the
4651
* 'mainClassName' of the project or the 'main' of the 'run' task. If not specified the
4752
* 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
@@ -172,6 +172,7 @@ private void repackage(File file) {
172172
}
173173
Repackager repackager = new LoggingRepackager(file);
174174
setMainClass(repackager);
175+
repackager.setLauncherClass(this.extension.getLauncherClass());
175176
repackager.setLayout(this.extension.convertLayout());
176177
repackager.setBackupSource(this.extension.isBackupSource());
177178
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
@@ -241,7 +247,9 @@ private Manifest buildManifest(JarFile source) throws IOException {
241247
if (startClass == null) {
242248
startClass = findMainMethod(source);
243249
}
244-
String launcherClassName = this.layout.getLauncherClassName();
250+
String launcherClassName = (launcherClass != null)
251+
? launcherClass
252+
: layout.getLauncherClassName();
245253
if (launcherClassName != null) {
246254
manifest.getMainAttributes()
247255
.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
@@ -103,6 +103,12 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
103103
@Parameter
104104
private String classifier;
105105

106+
/**
107+
* Name of the launcher class; overrides the one specified by layout.
108+
*/
109+
@Parameter
110+
private String launcherClass;
111+
106112
/**
107113
* The name of the main class. If not specified the first compiled class found that
108114
* contains a 'main' method will be used.
@@ -182,6 +188,7 @@ protected String findMainMethod(JarFile source) throws IOException {
182188
}
183189
};
184190
repackager.setMainClass(this.mainClass);
191+
repackager.setLauncherClass(this.launcherClass);
185192

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

0 commit comments

Comments
 (0)