Fix Gradle plugin task dependencies broken by removal of app plugin

8673250 updated the plugin so that the application plugin is no longer
applied by default. This exposed three problems:

 1. bootRepackage may run before findMainClass has run, leaving it with
    an unknown main class.
 2. findMainClass may run before the classes have been built, making it
    unable to find the main class by examining the class files
 3. The project's mainClassName property was still being used as a
    convention for the bootRun task's main property. If the application
    plugin has not be applied, then this property does not exist.

The first problem has been addressed by configuring bootRepackage to
depend on findMainClass.

The second problem has been addressed by configuring the main source
set's output as an input of findMainClass, and configuring findMainClass
to depend on the tasks that build the output.

The third problem has been addressed by only using the mainClassName
property if it exists and its value is not null. We then fallback to
using the mainClassName property on the project's extra properties in
the same way. 

See gh-2679
This commit is contained in:
Andy Wilkinson
2015-07-22 13:47:24 +01:00
parent 8673250955
commit 434f528e0a
9 changed files with 73 additions and 21 deletions

View File

@@ -43,8 +43,7 @@ public class InstallTests {
// "install" from the application plugin was renamed "installApp" in Gradle
// 1.0
this.project.newBuild().forTasks("installApp")
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace", "--info")
.run();
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
}
}

View File

@@ -23,7 +23,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
/**
* Tests for using the Gradle plugin's support for installing artifacts
* Tests for configuring a project's main class
*
* @author Dave Syer
*/
@@ -35,11 +35,11 @@ public class MainClassTests {
@BeforeClass
public static void createProject() throws IOException {
project = new ProjectCreator().createProject("main-in-run");
project = new ProjectCreator().createProject("main-in-boot-run");
}
@Test
public void buildFromRunTask() {
public void mainFromBootRun() {
project.newBuild().forTasks("build")
.withArguments("-PbootVersion=" + BOOT_VERSION, "--info").run();
}

View File

@@ -12,7 +12,7 @@ apply plugin: 'spring-boot'
group = 'flatdir'
version = '0.0.0'
run {
bootRun {
main = 'Foo'
}

View File

@@ -10,11 +10,12 @@ buildscript {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'spring-boot'
apply plugin: 'application'
group = 'installer'
version = '0.0.0'
run {
bootRun {
main = 'org.springframework.boot.SpringApplication'
}

View File

@@ -14,7 +14,7 @@ apply plugin: 'spring-boot'
group = 'installer'
version = '0.0.0'
run {
bootRun {
main = 'org.springframework.boot.SpringApplication'
}