diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc
index d86915f04c2..74776a0af86 100644
--- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc
+++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc
@@ -829,8 +829,8 @@ and triggers a restart. In IntelliJ IDEA, building the project
====
As long as forking is enabled, you can also start your application by using the supported
build plugins (Maven and Gradle), since DevTools needs an isolated application
-classloader to operate properly. By default, Gradle and Maven do that when they detect
-DevTools on the classpath.
+classloader to operate properly. By default, the Gradle and Maven plugins fork the
+application process.
====
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-fork/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-fork/pom.xml
index 06d0784d02e..2a3f19079cb 100644
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-fork/pom.xml
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-fork/pom.xml
@@ -22,9 +22,6 @@
run
-
- true
-
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/pom.xml
index 0b8a5144b37..05049787147 100644
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/pom.xml
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/pom.xml
@@ -23,7 +23,6 @@
run
- true
foo
bar
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run/pom.xml
index 75990e21364..19743c2c37a 100644
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run/pom.xml
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run/pom.xml
@@ -22,6 +22,9 @@
run
+
+ false
+
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/invoker.properties b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/invoker.properties
deleted file mode 100644
index 793d89fcd37..00000000000
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/invoker.properties
+++ /dev/null
@@ -1 +0,0 @@
-invoker.goals=clean verify
\ No newline at end of file
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/pom.xml
deleted file mode 100644
index 1d9e83497bf..00000000000
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/pom.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-
-
- 4.0.0
- org.springframework.boot.maven.it
- start-stop-automatic-fork
- 0.0.1.BUILD-SNAPSHOT
-
- UTF-8
- @java.version@
- @java.version@
-
-
-
-
- org.codehaus.mojo
- build-helper-maven-plugin
- @build-helper-maven-plugin.version@
-
-
- reserve-jmx-port
-
- reserve-network-port
-
- process-resources
-
-
- jmx.port
-
-
-
-
-
-
- @project.groupId@
- @project.artifactId@
- @project.version@
-
-
- pre-integration-test
-
- start
-
-
- -Dfoo=bar
-
-
-
- post-integration-test
-
- stop
-
-
-
-
- ${jmx.port}
-
-
-
-
-
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/src/main/java/org/test/SampleApplication.java
deleted file mode 100644
index 4d46db5a5da..00000000000
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/src/main/java/org/test/SampleApplication.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2012-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.test;
-
-import java.lang.management.ManagementFactory;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-/**
- * This sample app simulates the JMX Mbean that is exposed by the Spring Boot application.
- */
-public class SampleApplication {
-
- private static final Object lock = new Object();
-
- public static void main(String[] args) throws Exception {
- MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
- ObjectName name = new ObjectName(
- "org.springframework.boot:type=Admin,name=SpringApplication");
- SpringApplicationAdmin mbean = new SpringApplicationAdmin();
- mbs.registerMBean(mbean, name);
-
- // Flag the app as ready
- mbean.ready = true;
-
- int waitAttempts = 0;
- while (!mbean.shutdownInvoked) {
- if (waitAttempts > 30) {
- throw new IllegalStateException(
- "Shutdown should have been invoked by now");
- }
- synchronized (lock) {
- lock.wait(250);
- }
- waitAttempts++;
- }
- }
-
- public interface SpringApplicationAdminMXBean {
-
- boolean isReady();
-
- void shutdown();
-
- }
-
- static class SpringApplicationAdmin implements SpringApplicationAdminMXBean {
-
- private boolean ready;
-
- private boolean shutdownInvoked;
-
- @Override
- public boolean isReady() {
- System.out.println("isReady: " + this.ready);
- return this.ready;
- }
-
- @Override
- public void shutdown() {
- this.shutdownInvoked = true;
- System.out.println("Shutdown requested");
- }
-
- }
-
-}
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/verify.groovy b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/verify.groovy
deleted file mode 100644
index 5aa87af6830..00000000000
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/verify.groovy
+++ /dev/null
@@ -1,5 +0,0 @@
-import static org.junit.Assert.assertTrue
-
-def file = new File(basedir, "build.log")
-assertTrue 'Start should have waited for application to be ready', file.text.contains("isReady: true")
-assertTrue 'Shutdown should have been invoked', file.text.contains("Shutdown requested")
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-fork/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-fork/pom.xml
index 009e876a5c2..3c533ce7669 100644
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-fork/pom.xml
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-fork/pom.xml
@@ -50,7 +50,6 @@
- true
${jmx.port}
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop/pom.xml
index 8a1a8ad6714..c0791845470 100644
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop/pom.xml
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop/pom.xml
@@ -30,6 +30,9 @@
+
+ false
+
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java
index fa1b814caf5..c6cdaf7d5a9 100644
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java
@@ -75,8 +75,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
private boolean addResources = false;
/**
- * Path to agent jar. NOTE: the use of agents means that processes will be started by
- * forking a new JVM.
+ * Path to agent jar. NOTE: a forked process is required to use this feature.
* @since 1.0
* @deprecated since 2.2.0 in favor of {@code agents}
*/
@@ -85,8 +84,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
private File[] agent;
/**
- * Path to agent jars. NOTE: the use of agents means that processes will be started by
- * forking a new JVM.
+ * Path to agent jars. NOTE: a forked process is required to use this feature.
* @since 2.2
*/
@Parameter(property = "spring-boot.run.agents")
@@ -101,8 +99,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
/**
* Current working directory to use for the application. If not specified, basedir
- * will be used. NOTE: the use of working directory means that processes will be
- * started by forking a new JVM.
+ * will be used. NOTE: a forked process is required to use this feature.
* @since 1.5
*/
@Parameter(property = "spring-boot.run.workingDirectory")
@@ -111,16 +108,15 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
/**
* JVM arguments that should be associated with the forked process used to run the
* application. On command line, make sure to wrap multiple values between quotes.
- * NOTE: the use of JVM arguments means that processes will be started by forking a
- * new JVM.
+ * NOTE: a forked process is required to use this feature.
* @since 1.1
*/
@Parameter(property = "spring-boot.run.jvmArguments")
private String jvmArguments;
/**
- * List of JVM system properties to pass to the process. NOTE: the use of system
- * properties means that processes will be started by forking a new JVM.
+ * List of JVM system properties to pass to the process. NOTE: a forked process is
+ * required to use this feature.
* @since 2.1
*/
@Parameter
@@ -128,8 +124,8 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
/**
* List of Environment variables that should be associated with the forked process
- * used to run the application. NOTE: the use of Environment variables means that
- * processes will be started by forking a new JVM.
+ * used to run the application. NOTE: a forked process is required to use this
+ * feature.
* @since 2.1
*/
@Parameter
@@ -177,13 +173,13 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
private File classesDirectory;
/**
- * Flag to indicate if the run processes should be forked. {@code fork} is
- * automatically enabled if an agent, jvmArguments or working directory are specified,
- * or if devtools is present.
+ * Flag to indicate if the run processes should be forked. Disabling forking will
+ * disable some features such as an agent, custom JVM arguments, devtools or
+ * specifying the working directory to use.
* @since 1.2
*/
- @Parameter(property = "spring-boot.run.fork")
- private Boolean fork;
+ @Parameter(property = "spring-boot.run.fork", defaultValue = "true")
+ private boolean fork;
/**
* Flag to include the test classpath when running.
@@ -213,15 +209,16 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
* @return {@code true} if the application process should be forked
*/
protected boolean isFork() {
- return (Boolean.TRUE.equals(this.fork)
- || (this.fork == null && enableForkByDefault()));
+ return this.fork;
}
/**
* Specify if fork should be enabled by default.
* @return {@code true} if fork should be enabled by default
* @see #logDisabledFork()
+ * @deprecated as of 2.2.0 in favour of enabling forking by default.
*/
+ @Deprecated
protected boolean enableForkByDefault() {
return hasAgent() || hasJvmArgs() || hasEnvVariables()
|| hasWorkingDirectorySet();
@@ -264,7 +261,6 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
/**
* Log a warning indicating that fork mode has been explicitly disabled while some
* conditions are present that require to enable it.
- * @see #enableForkByDefault()
*/
protected void logDisabledFork() {
if (getLog().isWarnEnabled()) {
@@ -273,9 +269,8 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
}
if (hasJvmArgs()) {
RunArguments runArguments = resolveJvmArguments();
- getLog().warn("Fork mode disabled, ignoring JVM argument(s) [" + Arrays
- .stream(runArguments.asArray()).collect(Collectors.joining(" "))
- + "]");
+ getLog().warn("Fork mode disabled, ignoring JVM argument(s) ["
+ + String.join(" ", runArguments.asArray()) + "]");
}
if (hasWorkingDirectorySet()) {
getLog().warn(
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java
index 010369758d3..3119fbfeb4e 100644
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java
@@ -54,6 +54,7 @@ public class RunMojo extends AbstractRunMojo {
private Boolean hasDevtools;
@Override
+ @Deprecated
protected boolean enableForkByDefault() {
return super.enableForkByDefault() || hasDevtools();
}
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StartMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StartMojo.java
index 5a4437d5c19..80f69089e01 100644
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StartMojo.java
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StartMojo.java
@@ -67,8 +67,7 @@ public class StartMojo extends AbstractRunMojo {
private String jmxName = SpringApplicationAdminClient.DEFAULT_OBJECT_NAME;
/**
- * The port to use to expose the platform MBeanServer if the application needs to be
- * forked.
+ * The port to use to expose the platform MBeanServer if the application is forked.
*/
@Parameter
private int jmxPort = 9001;
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/examples/run-debug.apt.vm b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/examples/run-debug.apt.vm
index 679301a8aaf..d8d5d0261ba 100644
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/examples/run-debug.apt.vm
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/examples/run-debug.apt.vm
@@ -6,10 +6,8 @@
2014-05-14
-----
- By default, the <<>> goal runs in the same process unless jvm arguments or an agent have been specified. You
- can enable or disable forking explicitly using the <<>> attribute.
-
- If you need to fork the process and debug it you can add the necessary JVM arguments to enable remote debugging. The
+ By default, the <<>> goal runs your application in a forked process. If you need to
+ debug it, you should add the necessary JVM arguments to enable remote debugging. The
following configuration suspend the process until a debugger has joined on port 5005:
---
@@ -38,8 +36,8 @@
---
- Note that since you specified some JVM arguments, the process is forked automatically. These arguments can be
- specified on the command line as well, make sure to wrap that properly, that is:
+ These arguments can be specified on the command line as well, make sure to wrap that
+ properly, that is:
---
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/usage.apt.vm b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/usage.apt.vm
index 8572f23b5b2..a7702fc32ba 100644
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/usage.apt.vm
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/usage.apt.vm
@@ -130,10 +130,11 @@ Usage
mvn spring-boot:run
---
- By default the application is executed directly from the Maven JVM. If you need to run
- in a forked process you can use the 'fork' option. Forking will also occur if the
- 'jvmArguments', 'systemPropertyVariables', 'environmentVariables' or 'agent' options
- are specified, or if devtools is present.
+ By default the application is executed in a forked process. Although this is not
+ recommended, it is possible to execute the application directly from the Maven JVM by
+ disabling the <<>> property. Doing so means that <<>>,
+ <<>>, <<>> and <<>> options are
+ ignored.
If you need to specify some JVM arguments (i.e. for debugging purposes), you can use
the <<>> parameter, see {{{./examples/run-debug.html}Debug the application}}