Use mainClassName consistently across BootRun, BootJar, and BootWar
Previously, BootRun used the main property to configure the name of the main class to run while BootJar and BootWar used the mainClass property. Both were different to the application plugin which provides a mainClassName project property. This commit updates BootRun, BootJar, and BootWar to change the name of the property used to configure the name of the main class to be mainClassName. This makes the three Boot-specific tasks consistent with each other, and also aligns them with Gradle's own application plugin. Closes gh-10622
This commit is contained in:
@@ -85,7 +85,8 @@ By default, the executable archive's main class will be configured automatically
|
||||
looking for a class with a `public static void main(String[])` method in directories on
|
||||
the task's classpath.
|
||||
|
||||
The main class can also be configured explicitly using the task's `mainClass` property:
|
||||
The main class can also be configured explicitly using the task's `mainClassName`
|
||||
property:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
|
||||
@@ -11,8 +11,8 @@ To run your application without first building an archive use the `bootRun` task
|
||||
The `bootRun` task is automatically configured to use the runtime classpath of the
|
||||
main source set. By default, the main class will be discovered by looking for a class
|
||||
with a `public static void main(String[])` method in directories on the task's
|
||||
classpath. The main class can also be configured explicitly using the task's `main`
|
||||
property:
|
||||
classpath. The main class can also be configured explicitly using the task's
|
||||
`mainClassName` property:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
|
||||
@@ -20,5 +20,5 @@ bootJar {
|
||||
// end::classifier[]
|
||||
|
||||
bootJar {
|
||||
mainClass = 'com.example.Application'
|
||||
mainClassName = 'com.example.Application'
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
bootJar {
|
||||
mainClass 'com.example.ExampleApplication'
|
||||
mainClassName 'com.example.ExampleApplication'
|
||||
}
|
||||
|
||||
// tag::custom-launch-script[]
|
||||
|
||||
@@ -8,7 +8,7 @@ apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
bootJar {
|
||||
mainClass 'com.example.ExampleApplication'
|
||||
mainClassName 'com.example.ExampleApplication'
|
||||
}
|
||||
|
||||
// tag::include-launch-script[]
|
||||
|
||||
@@ -8,7 +8,7 @@ apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
bootJar {
|
||||
mainClass 'com.example.ExampleApplication'
|
||||
mainClassName 'com.example.ExampleApplication'
|
||||
}
|
||||
|
||||
// tag::launch-script-properties[]
|
||||
|
||||
@@ -9,6 +9,6 @@ apply plugin: 'java'
|
||||
|
||||
// tag::main-class[]
|
||||
bootJar {
|
||||
mainClass = 'com.example.ExampleApplication'
|
||||
mainClassName = 'com.example.ExampleApplication'
|
||||
}
|
||||
// end::main-class[]
|
||||
|
||||
@@ -16,7 +16,7 @@ dependencies {
|
||||
}
|
||||
|
||||
bootJar {
|
||||
mainClass 'com.example.ExampleApplication'
|
||||
mainClassName 'com.example.ExampleApplication'
|
||||
}
|
||||
|
||||
// tag::requires-unpack[]
|
||||
|
||||
@@ -8,7 +8,7 @@ apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'war'
|
||||
|
||||
bootWar {
|
||||
mainClass 'com.example.ExampleApplication'
|
||||
mainClassName 'com.example.ExampleApplication'
|
||||
classpath file('spring-boot-devtools-1.2.3.RELEASE.jar')
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'war'
|
||||
|
||||
bootWar {
|
||||
mainClass 'com.example.ExampleApplication'
|
||||
mainClassName 'com.example.ExampleApplication'
|
||||
}
|
||||
|
||||
// tag::properties-launcher[]
|
||||
|
||||
@@ -14,6 +14,6 @@ mainClassName = 'com.example.ExampleApplication'
|
||||
|
||||
task configuredMainClass {
|
||||
doLast {
|
||||
println bootRun.main
|
||||
println bootRun.mainClassName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ apply plugin: 'java'
|
||||
|
||||
// tag::main[]
|
||||
bootRun {
|
||||
main = 'com.example.ExampleApplication'
|
||||
mainClassName = 'com.example.ExampleApplication'
|
||||
}
|
||||
// end::main[]
|
||||
|
||||
task configuredMainClass {
|
||||
doLast {
|
||||
println bootRun.main
|
||||
println bootRun.mainClassName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ final class JavaPluginAction implements PluginApplicationAction {
|
||||
.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
|
||||
return mainSourceSet.getRuntimeClasspath();
|
||||
});
|
||||
bootJar.conventionMapping("mainClass",
|
||||
bootJar.conventionMapping("mainClassName",
|
||||
new MainClassConvention(project, bootJar::getClasspath));
|
||||
return bootJar;
|
||||
}
|
||||
@@ -112,7 +112,7 @@ final class JavaPluginAction implements PluginApplicationAction {
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}));
|
||||
run.setMain(
|
||||
run.setMainClassName(
|
||||
project.provider(new MainClassConvention(project, run::getClasspath)));
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class WarPluginAction implements PluginApplicationAction {
|
||||
bootWar.providedClasspath(providedRuntimeConfiguration(project));
|
||||
ArchivePublishArtifact artifact = new ArchivePublishArtifact(bootWar);
|
||||
this.singlePublishedArtifact.addCandidate(artifact);
|
||||
bootWar.conventionMapping("mainClass",
|
||||
bootWar.conventionMapping("mainClassName",
|
||||
new MainClassConvention(project, bootWar::getClasspath));
|
||||
}
|
||||
|
||||
|
||||
@@ -35,20 +35,20 @@ import org.gradle.api.tasks.Optional;
|
||||
public interface BootArchive extends Task {
|
||||
|
||||
/**
|
||||
* Returns the main class of the application.
|
||||
* Returns the name of the main class of the application.
|
||||
*
|
||||
* @return the main class
|
||||
* @return the main class name
|
||||
*/
|
||||
@Input
|
||||
@Optional
|
||||
String getMainClass();
|
||||
String getMainClassName();
|
||||
|
||||
/**
|
||||
* Sets the main class of the application.
|
||||
* Sets the name of the main class of the application.
|
||||
*
|
||||
* @param mainClass the main class of the application
|
||||
* @param mainClassName the name of the main class of the application
|
||||
*/
|
||||
void setMainClass(String mainClass);
|
||||
void setMainClassName(String mainClassName);
|
||||
|
||||
/**
|
||||
* Adds Ant-style patterns that identify files that must be unpacked from the archive
|
||||
|
||||
@@ -73,10 +73,10 @@ class BootArchiveSupport {
|
||||
configureExclusions();
|
||||
}
|
||||
|
||||
void configureManifest(Jar jar, String mainClass) {
|
||||
void configureManifest(Jar jar, String mainClassName) {
|
||||
Attributes attributes = jar.getManifest().getAttributes();
|
||||
attributes.putIfAbsent("Main-Class", this.loaderMainClass);
|
||||
attributes.putIfAbsent("Start-Class", mainClass);
|
||||
attributes.putIfAbsent("Start-Class", mainClassName);
|
||||
}
|
||||
|
||||
CopyAction createCopyAction(Jar jar) {
|
||||
|
||||
@@ -42,7 +42,7 @@ public class BootJar extends Jar implements BootArchive {
|
||||
|
||||
private FileCollection classpath;
|
||||
|
||||
private String mainClass;
|
||||
private String mainClassName;
|
||||
|
||||
/**
|
||||
* Creates a new {@code BootJar} task.
|
||||
@@ -63,7 +63,7 @@ public class BootJar extends Jar implements BootArchive {
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
this.support.configureManifest(this, getMainClass());
|
||||
this.support.configureManifest(this, getMainClassName());
|
||||
super.copy();
|
||||
}
|
||||
|
||||
@@ -73,13 +73,13 @@ public class BootJar extends Jar implements BootArchive {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMainClass() {
|
||||
return this.mainClass;
|
||||
public String getMainClassName() {
|
||||
return this.mainClassName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMainClass(String mainClass) {
|
||||
this.mainClass = mainClass;
|
||||
public void setMainClassName(String mainClassName) {
|
||||
this.mainClassName = mainClassName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,7 +41,7 @@ public class BootWar extends War implements BootArchive {
|
||||
private final BootArchiveSupport support = new BootArchiveSupport(
|
||||
"org.springframework.boot.loader.WarLauncher", this::resolveZipCompression);
|
||||
|
||||
private String mainClass;
|
||||
private String mainClassName;
|
||||
|
||||
private FileCollection providedClasspath;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class BootWar extends War implements BootArchive {
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
this.support.configureManifest(this, getMainClass());
|
||||
this.support.configureManifest(this, getMainClassName());
|
||||
super.copy();
|
||||
}
|
||||
|
||||
@@ -67,13 +67,13 @@ public class BootWar extends War implements BootArchive {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMainClass() {
|
||||
return this.mainClass;
|
||||
public String getMainClassName() {
|
||||
return this.mainClassName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMainClass(String mainClass) {
|
||||
this.mainClass = mainClass;
|
||||
public void setMainClassName(String mainClass) {
|
||||
this.mainClassName = mainClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.gradle.process.JavaExecSpec;
|
||||
*/
|
||||
public class BootRun extends DefaultTask {
|
||||
|
||||
private final PropertyState<String> main = getProject().property(String.class);
|
||||
private final PropertyState<String> mainClassName = getProject().property(String.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private final PropertyState<List<String>> jvmArgs = (PropertyState<List<String>>) (Object) getProject()
|
||||
@@ -85,26 +85,26 @@ public class BootRun extends DefaultTask {
|
||||
* Returns the name of the main class to be run.
|
||||
* @return the main class name or {@code null}
|
||||
*/
|
||||
public String getMain() {
|
||||
return this.main.getOrNull();
|
||||
public String getMainClassName() {
|
||||
return this.mainClassName.getOrNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the main class to be executed using the given {@code mainProvider}.
|
||||
* Sets the name of the main class to be executed using the given {@code mainClassNameProvider}.
|
||||
*
|
||||
* @param mainProvider provider of the main class name
|
||||
* @param mainClassNameProvider provider of the main class name
|
||||
*/
|
||||
public void setMain(Provider<String> mainProvider) {
|
||||
this.main.set(mainProvider);
|
||||
public void setMainClassName(Provider<String> mainClassNameProvider) {
|
||||
this.mainClassName.set(mainClassNameProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the main class to be run.
|
||||
* Sets the name of the main class to be run.
|
||||
*
|
||||
* @param main the main class name
|
||||
* @param mainClassName the main class name
|
||||
*/
|
||||
public void setMain(String main) {
|
||||
this.main.set(main);
|
||||
public void setMainClassName(String mainClassName) {
|
||||
this.mainClassName.set(mainClassName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,7 +171,7 @@ public class BootRun extends DefaultTask {
|
||||
public void run() {
|
||||
getProject().javaexec((spec) -> {
|
||||
spec.classpath(this.classpath);
|
||||
spec.setMain(this.main.getOrNull());
|
||||
spec.setMain(this.mainClassName.getOrNull());
|
||||
if (this.jvmArgs.isPresent()) {
|
||||
spec.setJvmArgs(this.jvmArgs.get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user