Allow custom repackage task to be used without a global main class
Closes gh-5956
This commit is contained in:
@@ -159,6 +159,17 @@ public class RepackagingTests {
|
||||
assertFalse(isDevToolsJarIncluded(repackageFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customRepackagingTaskWithOwnMainClassNameAnNoGlobalMainClassName() {
|
||||
project.newBuild().forTasks("clean", "customRepackagedJarWithOwnMainClass")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true",
|
||||
"-PexcludeDevtools=false", "-PnoMainClass=true")
|
||||
.run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
assertTrue(new File(buildLibs, "custom.jar").exists());
|
||||
assertTrue(new File(buildLibs, "custom.jar.original").exists());
|
||||
}
|
||||
|
||||
private boolean isDevToolsJarIncluded(File repackageFile) throws IOException {
|
||||
JarFile jarFile = new JarFile(repackageFile);
|
||||
try {
|
||||
|
||||
@@ -23,7 +23,9 @@ dependencies {
|
||||
}
|
||||
|
||||
springBoot {
|
||||
mainClass = 'foo.bar.Baz'
|
||||
if (!project.hasProperty("noMainClass")) {
|
||||
mainClass = 'foo.bar.Baz'
|
||||
}
|
||||
excludeDevtools = Boolean.valueOf(project.excludeDevtools)
|
||||
}
|
||||
|
||||
@@ -50,3 +52,8 @@ task customRepackagedJar(type: BootRepackage, dependsOn: customJar) {
|
||||
task customRepackagedJarWithStringReference(type: BootRepackage, dependsOn: customJar) {
|
||||
withJarTask = 'customJar'
|
||||
}
|
||||
|
||||
task customRepackagedJarWithOwnMainClass(type: BootRepackage, dependsOn: customJar) {
|
||||
withJarTask = customJar
|
||||
mainClass = 'foo.bar.Baz'
|
||||
}
|
||||
|
||||
@@ -240,14 +240,16 @@ public class RepackageTask extends DefaultTask {
|
||||
}
|
||||
|
||||
private void setMainClass(Repackager repackager) {
|
||||
String mainClass;
|
||||
String mainClass = null;
|
||||
if (getProject().hasProperty("mainClassName")) {
|
||||
mainClass = (String) getProject().property("mainClassName");
|
||||
}
|
||||
else {
|
||||
ExtraPropertiesExtension extraProperties = (ExtraPropertiesExtension) getProject()
|
||||
.getExtensions().getByName("ext");
|
||||
mainClass = (String) extraProperties.get("mainClassName");
|
||||
if (extraProperties.has("mainClassName")) {
|
||||
mainClass = (String) extraProperties.get("mainClassName");
|
||||
}
|
||||
}
|
||||
if (RepackageTask.this.mainClass != null) {
|
||||
mainClass = RepackageTask.this.mainClass;
|
||||
@@ -262,8 +264,13 @@ public class RepackageTask extends DefaultTask {
|
||||
.property("main");
|
||||
}
|
||||
}
|
||||
getLogger().info("Setting mainClass: " + mainClass);
|
||||
repackager.setMainClass(mainClass);
|
||||
if (mainClass != null) {
|
||||
getLogger().info("Setting mainClass: " + mainClass);
|
||||
repackager.setMainClass(mainClass);
|
||||
}
|
||||
else {
|
||||
getLogger().info("No mainClass configured");
|
||||
}
|
||||
}
|
||||
|
||||
private LaunchScript getLaunchScript() throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user