Make use of Gradle's application plugin optional when using Boot plugin
Previously, the Spring Boot Gradle plugin would always apply the application plugin to a project. It then piggy-backed on the application plugin’s mainClassName and applicationDefaultJvmArgs properties for the configuration of the bootRun task. This commit updates the Spring Boot Gradle plugin so that it no longer applies the application plugin. If the user applies the application plugin then its configuration will be used, but it’s a no longer requirement. Users who do not need the application plugin, but who were using the mainClassName or applicationDefaultJvmArgs properties will need to change their builds as a result of this change as those properties will no longer exist. As before, the mainClassName can be configured on the springBoot extension: springBoot { mainClassName 'com.example.YourApplication' } The applicationDefaultJvmArgs property can be used, but it must now be declared with the project's ext block. For example: ext { applicationDefaultJvmArgs = [ '-Dcom.example.property=true' ] } Closes gh-2679
This commit is contained in:
parent
dbc22f6f07
commit
8673250955
|
@ -768,7 +768,7 @@ entropy for session keys.)
|
|||
|
||||
[[using-boot-running-with-the-gradle-plugin]]
|
||||
=== Using the Gradle plugin
|
||||
The Spring Boot Gradle plugin also includes a `run` goal which can be used to run
|
||||
The Spring Boot Gradle plugin also includes a `bootRun` task which can be used to run
|
||||
your application in an exploded form. The `bootRun` task is added whenever you import
|
||||
the `spring-boot-plugin`
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@ package org.springframework.boot.gradle
|
|||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.ApplicationPlugin
|
||||
import org.gradle.api.plugins.BasePlugin
|
||||
import org.gradle.api.plugins.JavaPlugin
|
||||
import org.springframework.boot.gradle.agent.AgentPluginFeatures
|
||||
import org.springframework.boot.gradle.dependencymanagement.DependencyManagementPluginFeatures
|
||||
|
@ -41,7 +39,6 @@ class SpringBootPlugin implements Plugin<Project> {
|
|||
project.getExtensions().create("springBoot", SpringBootPluginExtension)
|
||||
|
||||
project.getPlugins().apply(JavaPlugin)
|
||||
project.getPlugins().apply(ApplicationPlugin)
|
||||
|
||||
new AgentPluginFeatures().apply(project)
|
||||
new RepackagePluginFeatures().apply(project)
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.gradle.api.DefaultTask;
|
|||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.plugins.ApplicationPluginConvention;
|
||||
import org.gradle.api.plugins.ExtraPropertiesExtension;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
import org.springframework.boot.gradle.SpringBootPluginExtension;
|
||||
|
@ -33,14 +34,24 @@ import org.springframework.boot.loader.tools.MainClassFinder;
|
|||
*
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class FindMainClassTask extends DefaultTask {
|
||||
|
||||
@TaskAction
|
||||
public void setMainClassNameProperty() {
|
||||
Project project = getProject();
|
||||
if (project.property("mainClassName") == null) {
|
||||
project.setProperty("mainClassName", findMainClass());
|
||||
if (!project.hasProperty("mainClassName")
|
||||
|| project.property("mainClassName") == null) {
|
||||
String mainClass = findMainClass();
|
||||
if (project.hasProperty("mainClassName")) {
|
||||
project.setProperty("mainClassName", mainClass);
|
||||
}
|
||||
else {
|
||||
ExtraPropertiesExtension extraProperties = (ExtraPropertiesExtension) project
|
||||
.getExtensions().getByName("ext");
|
||||
extraProperties.set("mainClassName", mainClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,13 +69,14 @@ public class FindMainClassTask extends DefaultTask {
|
|||
|
||||
ApplicationPluginConvention application = (ApplicationPluginConvention) project
|
||||
.getConvention().getPlugins().get("application");
|
||||
// Try the Application extension setting
|
||||
if (mainClass == null && application.getMainClassName() != null) {
|
||||
|
||||
if (mainClass == null && application != null) {
|
||||
// Try the Application extension setting
|
||||
mainClass = application.getMainClassName();
|
||||
}
|
||||
|
||||
Task runTask = getProject().getTasks().getByName("run");
|
||||
if (mainClass == null && runTask.hasProperty("main")) {
|
||||
Task runTask = project.getTasks().findByName("run");
|
||||
if (mainClass == null && runTask != null) {
|
||||
mainClass = (String) runTask.property("main");
|
||||
}
|
||||
|
||||
|
@ -91,10 +103,10 @@ public class FindMainClassTask extends DefaultTask {
|
|||
if (bootExtension.getMainClass() == null) {
|
||||
bootExtension.setMainClass(mainClass);
|
||||
}
|
||||
if (application.getMainClassName() == null) {
|
||||
if (application != null && application.getMainClassName() == null) {
|
||||
application.setMainClassName(mainClass);
|
||||
}
|
||||
if (!runTask.hasProperty("main")) {
|
||||
if (runTask != null && !runTask.hasProperty("main")) {
|
||||
runTask.setProperty("main", mainClass);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue