Use application plugin properties by convention when it is applied
bootRun's main and jvmArgs properties use mainClassName and applicationDefaultJvmArgs respectively by convention. bootJar and bootWar's mainClass property uses mainClassName by convention.
This commit is contained in:
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.springframework.boot.gradle.bundling;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.gradle.testkit.runner.InvalidRunnerConfigurationException;
|
||||
import org.gradle.testkit.runner.TaskOutcome;
|
||||
@@ -97,4 +99,17 @@ public abstract class AbstractBootArchiveIntegrationTests {
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationPluginMainClassNameIsUsed() throws IOException {
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
try (JarFile jarFile = new JarFile(
|
||||
new File(this.gradleBuild.getProjectDir(), "build/libs")
|
||||
.listFiles()[0])) {
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
|
||||
.isEqualTo("com.example.CustomMain");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,6 +66,24 @@ public class BootRunIntegrationTests {
|
||||
assertThat(result.getOutput()).doesNotContain(urlOf("build/resources/main"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationPluginMainClassNameIsUsed() throws IOException {
|
||||
BuildResult result = this.gradleBuild.build("echoMainClassName");
|
||||
assertThat(result.task(":echoMainClassName").getOutcome())
|
||||
.isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
assertThat(result.getOutput())
|
||||
.contains("Main class name = com.example.CustomMainClass");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationPluginJvmArgumentsAreUsed() throws IOException {
|
||||
BuildResult result = this.gradleBuild.build("echoJvmArguments");
|
||||
assertThat(result.task(":echoJvmArguments").getOutcome())
|
||||
.isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
assertThat(result.getOutput())
|
||||
.contains("JVM arguments = [-Dcom.foo=bar, -Dcom.bar=baz]");
|
||||
}
|
||||
|
||||
private String urlOf(String path) throws IOException {
|
||||
return new File(this.gradleBuild.getProjectDir().getCanonicalFile(), path).toURI()
|
||||
.toURL().toString();
|
||||
|
||||
Reference in New Issue
Block a user