Ignore mainClassName property when its value is null
Closes gh-9892
This commit is contained in:
parent
c2459fce47
commit
36120d729a
|
|
@ -48,7 +48,10 @@ final class MainClassConvention implements Callable<Object> {
|
||||||
@Override
|
@Override
|
||||||
public Object call() throws Exception {
|
public Object call() throws Exception {
|
||||||
if (this.project.hasProperty("mainClassName")) {
|
if (this.project.hasProperty("mainClassName")) {
|
||||||
return this.project.property("mainClassName");
|
Object mainClassName = this.project.property("mainClassName");
|
||||||
|
if (mainClassName != null) {
|
||||||
|
return mainClassName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return resolveMainClass();
|
return resolveMainClass();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,7 @@ public class BootRunIntegrationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void basicExecution() throws IOException {
|
public void basicExecution() throws IOException {
|
||||||
File output = new File(this.gradleBuild.getProjectDir(),
|
copyApplication();
|
||||||
"src/main/java/com/example");
|
|
||||||
output.mkdirs();
|
|
||||||
FileSystemUtils.copyRecursively(new File("src/test/java/com/example"), output);
|
|
||||||
new File(this.gradleBuild.getProjectDir(), "src/main/resources").mkdirs();
|
new File(this.gradleBuild.getProjectDir(), "src/main/resources").mkdirs();
|
||||||
BuildResult result = this.gradleBuild.build("bootRun");
|
BuildResult result = this.gradleBuild.build("bootRun");
|
||||||
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
|
@ -58,10 +55,7 @@ public class BootRunIntegrationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sourceResourcesCanBeUsed() throws IOException {
|
public void sourceResourcesCanBeUsed() throws IOException {
|
||||||
File output = new File(this.gradleBuild.getProjectDir(),
|
copyApplication();
|
||||||
"src/main/java/com/example");
|
|
||||||
output.mkdirs();
|
|
||||||
FileSystemUtils.copyRecursively(new File("src/test/java/com/example"), output);
|
|
||||||
BuildResult result = this.gradleBuild.build("bootRun");
|
BuildResult result = this.gradleBuild.build("bootRun");
|
||||||
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
assertThat(result.getOutput()).contains("1. " + urlOf("src/main/resources"));
|
assertThat(result.getOutput()).contains("1. " + urlOf("src/main/resources"));
|
||||||
|
|
@ -78,6 +72,16 @@ public class BootRunIntegrationTests {
|
||||||
.contains("Main class name = com.example.CustomMainClass");
|
.contains("Main class name = com.example.CustomMainClass");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void applicationPluginMainClassNameIsNotUsedWhenItIsNull() throws IOException {
|
||||||
|
copyApplication();
|
||||||
|
BuildResult result = this.gradleBuild.build("echoMainClassName");
|
||||||
|
assertThat(result.task(":echoMainClassName").getOutcome())
|
||||||
|
.isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
assertThat(result.getOutput())
|
||||||
|
.contains("Main class name = com.example.BootRunApplication");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void applicationPluginJvmArgumentsAreUsed() throws IOException {
|
public void applicationPluginJvmArgumentsAreUsed() throws IOException {
|
||||||
BuildResult result = this.gradleBuild.build("echoJvmArguments");
|
BuildResult result = this.gradleBuild.build("echoJvmArguments");
|
||||||
|
|
@ -87,6 +91,13 @@ public class BootRunIntegrationTests {
|
||||||
.contains("JVM arguments = [-Dcom.foo=bar, -Dcom.bar=baz]");
|
.contains("JVM arguments = [-Dcom.foo=bar, -Dcom.bar=baz]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void copyApplication() throws IOException {
|
||||||
|
File output = new File(this.gradleBuild.getProjectDir(),
|
||||||
|
"src/main/java/com/example");
|
||||||
|
output.mkdirs();
|
||||||
|
FileSystemUtils.copyRecursively(new File("src/test/java/com/example"), output);
|
||||||
|
}
|
||||||
|
|
||||||
private String urlOf(String path) throws IOException {
|
private String urlOf(String path) throws IOException {
|
||||||
return new File(this.gradleBuild.getProjectDir().getCanonicalFile(), path).toURI()
|
return new File(this.gradleBuild.getProjectDir().getCanonicalFile(), path).toURI()
|
||||||
.toURL().toString();
|
.toURL().toString();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
buildscript {
|
||||||
|
dependencies {
|
||||||
|
classpath files(pluginClasspath.split(','))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'application'
|
||||||
|
apply plugin: 'org.springframework.boot'
|
||||||
|
|
||||||
|
task echoMainClassName {
|
||||||
|
dependsOn compileJava
|
||||||
|
doLast {
|
||||||
|
println 'Main class name = ' + bootRun.main
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue