Skip to content

Commit 09696c9

Browse files
committed
Deprecate running an application in the Maven JVM
This commit deprecates the "fork" property so that the application always runs in a dedicated process. This aligns with the behaviour of the Gradle plugin, and simplifies the lifecycle of certain features that would not work in a non-forked process. Closes gh-30479
1 parent 1da5a7a commit 09696c9

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/asciidoc/running.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ The plugin includes a run goal which can be used to launch your application from
99

1010
Application arguments can be specified using the `arguments` parameter, see <<run.examples.using-application-arguments,using application arguments>> for more details.
1111

12-
By default the application is executed in a forked process and setting properties on the command-line will not affect the application.
12+
The application is executed in a forked process and setting properties on the command-line will not affect the application.
1313
If you need to specify some JVM arguments (that is for debugging purposes), you can use the `jvmArguments` parameter, see <<run.examples.debug,Debug the application>> for more details.
1414
There is also explicit support for <<run.examples.system-properties,system properties>> and <<run.examples.environment-variables,environment variables>>.
1515

1616
As enabling a profile is quite common, there is dedicated `profiles` property that offers a shortcut for `-Dspring-boot.run.jvmArguments="-Dspring.profiles.active=dev"`, see <<run.examples.specify-active-profiles,Specify active profiles>>.
1717

18-
Although this is not recommended, it is possible to execute the application directly from the Maven JVM by disabling the `fork` property.
18+
Although this is not recommended (and deprecated), it is possible to execute the application directly from the Maven JVM by disabling the `fork` property.
1919
Doing so means that the `jvmArguments`, `systemPropertyVariables`, `environmentVariables` and `agents` options are ignored.
2020

2121
Spring Boot `devtools` is a module to improve the development-time experience when working on Spring Boot applications.
@@ -73,7 +73,7 @@ include::goals/run.adoc[leveloffset=+1]
7373

7474
[[run.examples.debug]]
7575
=== Debug the Application
76-
By default, the `run` goal runs your application in a forked process.
76+
The `run` goal runs your application in a forked process.
7777
If you need to debug it, you should add the necessary JVM arguments to enable remote debugging.
7878
The following configuration suspend the process until a debugger has joined on port 5005:
7979

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,14 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
192192
private File classesDirectory;
193193

194194
/**
195-
* Flag to indicate if the run processes should be forked. Disabling forking will
196-
* disable some features such as an agent, custom JVM arguments, devtools or
197-
* specifying the working directory to use.
195+
* Deprecated. Flag to indicate if the run processes should be forked. Disabling
196+
* forking will disable some features such as an agent, custom JVM arguments, devtools
197+
* or specifying the working directory to use.
198198
* @since 1.2.0
199+
* @deprecated since 2.7.0 for removal in 3.0.0 with no replacement
199200
*/
200201
@Parameter(property = "spring-boot.run.fork", defaultValue = "true")
202+
@Deprecated
201203
private boolean fork;
202204

203205
/**
@@ -226,7 +228,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
226228
/**
227229
* Specify if the application process should be forked.
228230
* @return {@code true} if the application process should be forked
231+
* @deprecated since 2.7.0 for removal in 3.0.0 with no replacement
229232
*/
233+
@Deprecated
230234
protected boolean isFork() {
231235
return this.fork;
232236
}
@@ -244,6 +248,7 @@ private boolean hasWorkingDirectorySet() {
244248
return this.workingDirectory != null;
245249
}
246250

251+
@SuppressWarnings("deprecation")
247252
private void run(String startClassName) throws MojoExecutionException, MojoFailureException {
248253
boolean fork = isFork();
249254
this.project.getProperties().setProperty("_spring.boot.fork.enabled", Boolean.toString(fork));
@@ -304,7 +309,9 @@ protected abstract void runWithForkedJvm(File workingDirectory, List<String> arg
304309
* @param arguments the class arguments
305310
* @throws MojoExecutionException in case of MOJO execution errors
306311
* @throws MojoFailureException in case of MOJO failures
312+
* @deprecated since 2.7.0 for removal in 3.0.0 with no replacement
307313
*/
314+
@Deprecated
308315
protected abstract void runWithMavenJvm(String startClassName, String... arguments)
309316
throws MojoExecutionException, MojoFailureException;
310317

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ protected void logDisabledFork() {
7171
}
7272

7373
@Override
74+
@SuppressWarnings("deprecation")
7475
protected RunArguments resolveJvmArguments() {
7576
RunArguments jvmArguments = super.resolveJvmArguments();
7677
if (isFork() && this.optimizedLaunch) {
@@ -114,6 +115,7 @@ private int forkJvm(File workingDirectory, List<String> args, Map<String, String
114115
}
115116

116117
@Override
118+
@Deprecated
117119
protected void runWithMavenJvm(String startClassName, String... arguments) throws MojoExecutionException {
118120
IsolatedThreadGroup threadGroup = new IsolatedThreadGroup(startClassName);
119121
Thread launchThread = new Thread(threadGroup, new LaunchRunner(startClassName, arguments), "main");

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ private RunProcess runProcess(File workingDirectory, List<String> args, Map<Stri
113113
}
114114

115115
@Override
116+
@SuppressWarnings("deprecation")
116117
protected RunArguments resolveApplicationArguments() {
117118
RunArguments applicationArguments = super.resolveApplicationArguments();
118119
applicationArguments.getArgs().addLast(ENABLE_MBEAN_PROPERTY);
@@ -123,6 +124,7 @@ protected RunArguments resolveApplicationArguments() {
123124
}
124125

125126
@Override
127+
@SuppressWarnings("deprecation")
126128
protected RunArguments resolveJvmArguments() {
127129
RunArguments jvmArguments = super.resolveJvmArguments();
128130
if (isFork()) {
@@ -138,6 +140,7 @@ protected RunArguments resolveJvmArguments() {
138140
}
139141

140142
@Override
143+
@Deprecated
141144
protected void runWithMavenJvm(String startClassName, String... arguments) throws MojoExecutionException {
142145
IsolatedThreadGroup threadGroup = new IsolatedThreadGroup(startClassName);
143146
Thread launchThread = new Thread(threadGroup, new LaunchRunner(startClassName, arguments),
@@ -171,6 +174,7 @@ private void waitForSpringApplication(long wait, int maxAttempts) throws MojoExe
171174
"Spring application did not start before the configured timeout (" + (wait * maxAttempts) + "ms");
172175
}
173176

177+
@SuppressWarnings("deprecation")
174178
private void waitForSpringApplication() throws MojoFailureException, MojoExecutionException {
175179
try {
176180
if (isFork()) {

0 commit comments

Comments
 (0)