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:
@@ -89,7 +89,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void basicArchiveCreation() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.execute();
|
||||
assertThat(this.task.getArchivePath().exists());
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
@@ -102,7 +102,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void classpathJarsArePackagedBeneathLibPath() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.classpath(this.temp.newFile("one.jar"), this.temp.newFile("two.jar"));
|
||||
this.task.execute();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
@@ -113,7 +113,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void classpathFoldersArePackagedBeneathClassesPath() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
File classpathFolder = this.temp.newFolder();
|
||||
File applicationClass = new File(classpathFolder,
|
||||
"com/example/Application.class");
|
||||
@@ -130,7 +130,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void loaderIsWrittenToTheRootOfTheJar() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.execute();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(jarFile.getEntry(
|
||||
@@ -143,7 +143,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
@Test
|
||||
public void loaderIsWrittenToTheRootOfTheJarWhenUsingThePropertiesLauncher()
|
||||
throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.execute();
|
||||
this.task.getManifest().getAttributes().put("Main-Class",
|
||||
"org.springframework.boot.loader.PropertiesLauncher");
|
||||
@@ -157,7 +157,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void unpackCommentIsAddedToEntryIdentifiedByAPattern() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.classpath(this.temp.newFile("one.jar"), this.temp.newFile("two.jar"));
|
||||
this.task.requiresUnpack("**/one.jar");
|
||||
this.task.execute();
|
||||
@@ -170,7 +170,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void unpackCommentIsAddedToEntryIdentifiedByASpec() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.classpath(this.temp.newFile("one.jar"), this.temp.newFile("two.jar"));
|
||||
this.task.requiresUnpack((element) -> element.getName().endsWith("two.jar"));
|
||||
this.task.execute();
|
||||
@@ -183,7 +183,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void launchScriptCanBePrepended() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.launchScript();
|
||||
this.task.execute();
|
||||
assertThat(Files.readAllBytes(this.task.getArchivePath().toPath()))
|
||||
@@ -200,7 +200,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void customLaunchScriptCanBePrepended() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
File customScript = this.temp.newFile("custom.script");
|
||||
Files.write(customScript.toPath(), Arrays.asList("custom script"),
|
||||
StandardOpenOption.CREATE);
|
||||
@@ -212,7 +212,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void launchScriptPropertiesAreReplaced() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.launchScript((configuration) -> configuration.getProperties()
|
||||
.put("initInfoProvides", "test property value"));
|
||||
this.task.execute();
|
||||
@@ -222,7 +222,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void customMainClassInTheManifestIsHonored() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.getManifest().getAttributes().put("Main-Class",
|
||||
"com.example.CustomLauncher");
|
||||
this.task.execute();
|
||||
@@ -240,7 +240,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void customStartClassInTheManifestIsHonored() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.getManifest().getAttributes().put("Start-Class",
|
||||
"com.example.CustomMain");
|
||||
this.task.execute();
|
||||
@@ -255,7 +255,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void fileTimestampPreservationCanBeDisabled() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.setPreserveFileTimestamps(false);
|
||||
this.task.execute();
|
||||
assertThat(this.task.getArchivePath().exists());
|
||||
@@ -271,7 +271,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void reproducibleOrderingCanBeEnabled() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.from(this.temp.newFile("bravo.txt"), this.temp.newFile("alpha.txt"),
|
||||
this.temp.newFile("charlie.txt"));
|
||||
this.task.setReproducibleFileOrder(true);
|
||||
@@ -292,7 +292,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void devtoolsJarIsExcludedByDefault() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.classpath(this.temp.newFile("spring-boot-devtools-0.1.2.jar"));
|
||||
this.task.execute();
|
||||
assertThat(this.task.getArchivePath().exists());
|
||||
@@ -304,7 +304,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void devtoolsJarCanBeIncluded() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.classpath(this.temp.newFile("spring-boot-devtools-0.1.2.jar"));
|
||||
this.task.setExcludeDevtools(false);
|
||||
this.task.execute();
|
||||
@@ -317,7 +317,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
public void allEntriesUseUnixPlatformAndUtf8NameEncoding() throws IOException {
|
||||
this.task.setMainClass("com.example.Main");
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.setMetadataCharset("UTF-8");
|
||||
File classpathFolder = this.temp.newFolder();
|
||||
File resource = new File(classpathFolder, "some-resource.xml");
|
||||
|
||||
@@ -38,7 +38,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
|
||||
@Test
|
||||
public void providedClasspathJarsArePackagedInWebInfLibProvided() throws IOException {
|
||||
getTask().setMainClass("com.example.Main");
|
||||
getTask().setMainClassName("com.example.Main");
|
||||
getTask().providedClasspath(this.temp.newFile("one.jar"),
|
||||
this.temp.newFile("two.jar"));
|
||||
getTask().execute();
|
||||
@@ -51,7 +51,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
@Test
|
||||
public void devtoolsJarIsExcludedByDefaultWhenItsOnTheProvidedClasspath()
|
||||
throws IOException {
|
||||
getTask().setMainClass("com.example.Main");
|
||||
getTask().setMainClassName("com.example.Main");
|
||||
getTask().providedClasspath(this.temp.newFile("spring-boot-devtools-0.1.2.jar"));
|
||||
getTask().execute();
|
||||
assertThat(getTask().getArchivePath().exists());
|
||||
@@ -65,7 +65,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
@Test
|
||||
public void devtoolsJarCanBeIncludedWhenItsOnTheProvidedClasspath()
|
||||
throws IOException {
|
||||
getTask().setMainClass("com.example.Main");
|
||||
getTask().setMainClassName("com.example.Main");
|
||||
getTask().providedClasspath(this.temp.newFile("spring-boot-devtools-0.1.2.jar"));
|
||||
getTask().setExcludeDevtools(false);
|
||||
getTask().execute();
|
||||
@@ -85,7 +85,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
orgFolder.mkdir();
|
||||
new File(orgFolder, "foo.txt").createNewFile();
|
||||
getTask().from(webappFolder);
|
||||
getTask().setMainClass("com.example.Main");
|
||||
getTask().setMainClassName("com.example.Main");
|
||||
getTask().execute();
|
||||
assertThat(getTask().getArchivePath().exists());
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
|
||||
|
||||
Reference in New Issue
Block a user