Skip to content

Commit a5537bd

Browse files
committed
Fork application process with Maven by default
Closes gh-16945
1 parent 3432044 commit a5537bd

File tree

15 files changed

+37
-191
lines changed

15 files changed

+37
-191
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,8 @@ and triggers a restart. In IntelliJ IDEA, building the project
829829
====
830830
As long as forking is enabled, you can also start your application by using the supported
831831
build plugins (Maven and Gradle), since DevTools needs an isolated application
832-
classloader to operate properly. By default, Gradle and Maven do that when they detect
833-
DevTools on the classpath.
832+
classloader to operate properly. By default, the Gradle and Maven plugins fork the
833+
application process.
834834
835835
====
836836

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-fork/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
<goals>
2323
<goal>run</goal>
2424
</goals>
25-
<configuration>
26-
<fork>true</fork>
27-
</configuration>
2825
</execution>
2926
</executions>
3027
</plugin>

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
<goal>run</goal>
2424
</goals>
2525
<configuration>
26-
<fork>true</fork>
2726
<profiles>
2827
<profile>foo</profile>
2928
<profile>bar</profile>

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<goals>
2323
<goal>run</goal>
2424
</goals>
25+
<configuration>
26+
<fork>false</fork>
27+
</configuration>
2528
</execution>
2629
</executions>
2730
</plugin>

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/invoker.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/pom.xml

Lines changed: 0 additions & 61 deletions
This file was deleted.

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/src/main/java/org/test/SampleApplication.java

Lines changed: 0 additions & 82 deletions
This file was deleted.

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/verify.groovy

Lines changed: 0 additions & 5 deletions
This file was deleted.

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-fork/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
</execution>
5151
</executions>
5252
<configuration>
53-
<fork>true</fork>
5453
<jmxPort>${jmx.port}</jmxPort>
5554
</configuration>
5655
</plugin>

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
</goals>
3131
</execution>
3232
</executions>
33+
<configuration>
34+
<fork>false</fork>
35+
</configuration>
3336
</plugin>
3437
</plugins>
3538
</build>

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
7575
private boolean addResources = false;
7676

7777
/**
78-
* Path to agent jar. NOTE: the use of agents means that processes will be started by
79-
* forking a new JVM.
78+
* Path to agent jar. NOTE: a forked process is required to use this feature.
8079
* @since 1.0
8180
* @deprecated since 2.2.0 in favor of {@code agents}
8281
*/
@@ -85,8 +84,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
8584
private File[] agent;
8685

8786
/**
88-
* Path to agent jars. NOTE: the use of agents means that processes will be started by
89-
* forking a new JVM.
87+
* Path to agent jars. NOTE: a forked process is required to use this feature.
9088
* @since 2.2
9189
*/
9290
@Parameter(property = "spring-boot.run.agents")
@@ -101,8 +99,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
10199

102100
/**
103101
* Current working directory to use for the application. If not specified, basedir
104-
* will be used. NOTE: the use of working directory means that processes will be
105-
* started by forking a new JVM.
102+
* will be used. NOTE: a forked process is required to use this feature.
106103
* @since 1.5
107104
*/
108105
@Parameter(property = "spring-boot.run.workingDirectory")
@@ -111,25 +108,24 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
111108
/**
112109
* JVM arguments that should be associated with the forked process used to run the
113110
* application. On command line, make sure to wrap multiple values between quotes.
114-
* NOTE: the use of JVM arguments means that processes will be started by forking a
115-
* new JVM.
111+
* NOTE: a forked process is required to use this feature.
116112
* @since 1.1
117113
*/
118114
@Parameter(property = "spring-boot.run.jvmArguments")
119115
private String jvmArguments;
120116

121117
/**
122-
* List of JVM system properties to pass to the process. NOTE: the use of system
123-
* properties means that processes will be started by forking a new JVM.
118+
* List of JVM system properties to pass to the process. NOTE: a forked process is
119+
* required to use this feature.
124120
* @since 2.1
125121
*/
126122
@Parameter
127123
private Map<String, String> systemPropertyVariables;
128124

129125
/**
130126
* List of Environment variables that should be associated with the forked process
131-
* used to run the application. NOTE: the use of Environment variables means that
132-
* processes will be started by forking a new JVM.
127+
* used to run the application. NOTE: a forked process is required to use this
128+
* feature.
133129
* @since 2.1
134130
*/
135131
@Parameter
@@ -177,13 +173,13 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
177173
private File classesDirectory;
178174

179175
/**
180-
* Flag to indicate if the run processes should be forked. {@code fork} is
181-
* automatically enabled if an agent, jvmArguments or working directory are specified,
182-
* or if devtools is present.
176+
* Flag to indicate if the run processes should be forked. Disabling forking will
177+
* disable some features such as an agent, custom JVM arguments, devtools or
178+
* specifying the working directory to use.
183179
* @since 1.2
184180
*/
185-
@Parameter(property = "spring-boot.run.fork")
186-
private Boolean fork;
181+
@Parameter(property = "spring-boot.run.fork", defaultValue = "true")
182+
private boolean fork;
187183

188184
/**
189185
* Flag to include the test classpath when running.
@@ -213,15 +209,16 @@ public void execute() throws MojoExecutionException, MojoFailureException {
213209
* @return {@code true} if the application process should be forked
214210
*/
215211
protected boolean isFork() {
216-
return (Boolean.TRUE.equals(this.fork)
217-
|| (this.fork == null && enableForkByDefault()));
212+
return this.fork;
218213
}
219214

220215
/**
221216
* Specify if fork should be enabled by default.
222217
* @return {@code true} if fork should be enabled by default
223218
* @see #logDisabledFork()
219+
* @deprecated as of 2.2.0 in favour of enabling forking by default.
224220
*/
221+
@Deprecated
225222
protected boolean enableForkByDefault() {
226223
return hasAgent() || hasJvmArgs() || hasEnvVariables()
227224
|| hasWorkingDirectorySet();
@@ -264,7 +261,6 @@ private void run(String startClassName)
264261
/**
265262
* Log a warning indicating that fork mode has been explicitly disabled while some
266263
* conditions are present that require to enable it.
267-
* @see #enableForkByDefault()
268264
*/
269265
protected void logDisabledFork() {
270266
if (getLog().isWarnEnabled()) {
@@ -273,9 +269,8 @@ protected void logDisabledFork() {
273269
}
274270
if (hasJvmArgs()) {
275271
RunArguments runArguments = resolveJvmArguments();
276-
getLog().warn("Fork mode disabled, ignoring JVM argument(s) [" + Arrays
277-
.stream(runArguments.asArray()).collect(Collectors.joining(" "))
278-
+ "]");
272+
getLog().warn("Fork mode disabled, ignoring JVM argument(s) ["
273+
+ String.join(" ", runArguments.asArray()) + "]");
279274
}
280275
if (hasWorkingDirectorySet()) {
281276
getLog().warn(

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class RunMojo extends AbstractRunMojo {
5454
private Boolean hasDevtools;
5555

5656
@Override
57+
@Deprecated
5758
protected boolean enableForkByDefault() {
5859
return super.enableForkByDefault() || hasDevtools();
5960
}

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StartMojo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public class StartMojo extends AbstractRunMojo {
6767
private String jmxName = SpringApplicationAdminClient.DEFAULT_OBJECT_NAME;
6868

6969
/**
70-
* The port to use to expose the platform MBeanServer if the application needs to be
71-
* forked.
70+
* The port to use to expose the platform MBeanServer if the application is forked.
7271
*/
7372
@Parameter
7473
private int jmxPort = 9001;

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/examples/run-debug.apt.vm

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
2014-05-14
77
-----
88

9-
By default, the <<<run>>> goal runs in the same process unless jvm arguments or an agent have been specified. You
10-
can enable or disable forking explicitly using the <<<fork>>> attribute.
11-
12-
If you need to fork the process and debug it you can add the necessary JVM arguments to enable remote debugging. The
9+
By default, the <<<run>>> goal runs your application in a forked process. If you need to
10+
debug it, you should add the necessary JVM arguments to enable remote debugging. The
1311
following configuration suspend the process until a debugger has joined on port 5005:
1412

1513
---
@@ -38,8 +36,8 @@
3836
</project>
3937
---
4038

41-
Note that since you specified some JVM arguments, the process is forked automatically. These arguments can be
42-
specified on the command line as well, make sure to wrap that properly, that is:
39+
These arguments can be specified on the command line as well, make sure to wrap that
40+
properly, that is:
4341

4442
---
4543
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/usage.apt.vm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,11 @@ Usage
130130
mvn spring-boot:run
131131
---
132132

133-
By default the application is executed directly from the Maven JVM. If you need to run
134-
in a forked process you can use the 'fork' option. Forking will also occur if the
135-
'jvmArguments', 'systemPropertyVariables', 'environmentVariables' or 'agent' options
136-
are specified, or if devtools is present.
133+
By default the application is executed in a forked process. Although this is not
134+
recommended, it is possible to execute the application directly from the Maven JVM by
135+
disabling the <<<fork>>> property. Doing so means that <<<jvmArguments>>>,
136+
<<<systemPropertyVariables>>>, <<<environmentVariables>>> and <<<agent>>> options are
137+
ignored.
137138

138139
If you need to specify some JVM arguments (i.e. for debugging purposes), you can use
139140
the <<<jvmArguments>>> parameter, see {{{./examples/run-debug.html}Debug the application}}

0 commit comments

Comments
 (0)