39
39
import org .apache .maven .toolchain .ToolchainManager ;
40
40
41
41
import org .springframework .boot .loader .tools .FileUtils ;
42
- import org .springframework .boot .maven .ClasspathBuilder .Classpath ;
43
42
44
43
/**
45
44
* Base class to run a Spring Boot application.
@@ -58,132 +57,151 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
58
57
59
58
/**
60
59
* The Maven project.
60
+ *
61
61
* @since 1.0.0
62
62
*/
63
63
@ Parameter (defaultValue = "${project}" , readonly = true , required = true )
64
64
private MavenProject project ;
65
65
66
66
/**
67
67
* The current Maven session. This is used for toolchain manager API calls.
68
+ *
68
69
* @since 2.3.0
69
70
*/
70
71
@ Parameter (defaultValue = "${session}" , readonly = true )
71
72
private MavenSession session ;
72
73
73
74
/**
74
75
* The toolchain manager to use to locate a custom JDK.
76
+ *
75
77
* @since 2.3.0
76
78
*/
77
79
@ Component
78
80
private ToolchainManager toolchainManager ;
79
81
80
82
/**
81
- * Add maven resources to the classpath directly, this allows live in-place editing of
82
- * resources. Duplicate resources are removed from {@code target/classes} to prevent
83
- * them from appearing twice if {@code ClassLoader.getResources()} is called. Please
84
- * consider adding {@code spring-boot-devtools} to your project instead as it provides
85
- * this feature and many more.
83
+ * Add maven resources to the classpath directly, this allows live in-place
84
+ * editing of resources. Duplicate resources are removed from
85
+ * {@code target/classes} to prevent them from appearing twice if
86
+ * {@code ClassLoader.getResources()} is called. Please consider adding
87
+ * {@code spring-boot-devtools} to your project instead as it provides this
88
+ * feature and many more.
89
+ *
86
90
* @since 1.0.0
87
91
*/
88
92
@ Parameter (property = "spring-boot.run.addResources" , defaultValue = "false" )
89
93
private boolean addResources = false ;
90
94
91
95
/**
92
96
* Path to agent jars.
97
+ *
93
98
* @since 2.2.0
94
99
*/
95
100
@ Parameter (property = "spring-boot.run.agents" )
96
101
private File [] agents ;
97
102
98
103
/**
99
104
* Flag to say that the agent requires -noverify.
105
+ *
100
106
* @since 1.0.0
101
107
*/
102
108
@ Parameter (property = "spring-boot.run.noverify" )
103
109
private boolean noverify = false ;
104
110
105
111
/**
106
- * Current working directory to use for the application. If not specified, basedir
107
- * will be used.
112
+ * Current working directory to use for the application. If not specified,
113
+ * basedir will be used.
114
+ *
108
115
* @since 1.5.0
109
116
*/
110
117
@ Parameter (property = "spring-boot.run.workingDirectory" )
111
118
private File workingDirectory ;
112
119
113
120
/**
114
- * JVM arguments that should be associated with the forked process used to run the
115
- * application. On command line, make sure to wrap multiple values between quotes.
121
+ * JVM arguments that should be associated with the forked process used to run
122
+ * the application. On command line, make sure to wrap multiple values between
123
+ * quotes.
124
+ *
116
125
* @since 1.1.0
117
126
*/
118
127
@ Parameter (property = "spring-boot.run.jvmArguments" )
119
128
private String jvmArguments ;
120
129
121
130
/**
122
131
* List of JVM system properties to pass to the process.
132
+ *
123
133
* @since 2.1.0
124
134
*/
125
135
@ Parameter
126
136
private Map <String , String > systemPropertyVariables ;
127
137
128
138
/**
129
- * List of Environment variables that should be associated with the forked process
130
- * used to run the application.
139
+ * List of Environment variables that should be associated with the forked
140
+ * process used to run the application.
141
+ *
131
142
* @since 2.1.0
132
143
*/
133
144
@ Parameter
134
145
private Map <String , String > environmentVariables ;
135
146
136
147
/**
137
148
* Arguments that should be passed to the application.
149
+ *
138
150
* @since 1.0.0
139
151
*/
140
152
@ Parameter
141
153
private String [] arguments ;
142
154
143
155
/**
144
156
* Arguments from the command line that should be passed to the application. Use
145
- * spaces to separate multiple arguments and make sure to wrap multiple values between
146
- * quotes. When specified, takes precedence over {@link #arguments}.
157
+ * spaces to separate multiple arguments and make sure to wrap multiple values
158
+ * between quotes. When specified, takes precedence over {@link #arguments}.
159
+ *
147
160
* @since 2.2.3
148
161
*/
149
162
@ Parameter (property = "spring-boot.run.arguments" )
150
163
private String commandlineArguments ;
151
164
152
165
/**
153
166
* The spring profiles to activate. Convenience shortcut of specifying the
154
- * 'spring.profiles.active' argument. On command line use commas to separate multiple
155
- * profiles.
167
+ * 'spring.profiles.active' argument. On command line use commas to separate
168
+ * multiple profiles.
169
+ *
156
170
* @since 1.3.0
157
171
*/
158
172
@ Parameter (property = "spring-boot.run.profiles" )
159
173
private String [] profiles ;
160
174
161
175
/**
162
- * The name of the main class. If not specified the first compiled class found that
163
- * contains a 'main' method will be used.
176
+ * The name of the main class. If not specified the first compiled class found
177
+ * that contains a 'main' method will be used.
178
+ *
164
179
* @since 1.0.0
165
180
*/
166
181
@ Parameter (property = "spring-boot.run.main-class" )
167
182
private String mainClass ;
168
183
169
184
/**
170
- * Additional classpath elements that should be added to the classpath. An element can
171
- * be a directory with classes and resources or a jar file.
185
+ * Additional classpath elements that should be added to the classpath. An
186
+ * element can be a directory with classes and resources or a jar file.
187
+ *
172
188
* @since 3.2.0
173
189
*/
174
190
@ Parameter (property = "spring-boot.run.additional-classpath-elements" )
175
191
private String [] additionalClasspathElements ;
176
192
177
193
/**
178
- * Directory containing the classes and resource files that should be used to run the
179
- * application.
194
+ * Directory containing the classes and resource files that should be used to
195
+ * run the application.
196
+ *
180
197
* @since 1.0.0
181
198
*/
182
199
@ Parameter (defaultValue = "${project.build.outputDirectory}" , required = true )
183
200
private File classesDirectory ;
184
201
185
202
/**
186
203
* Skip the execution.
204
+ *
187
205
* @since 1.3.2
188
206
*/
189
207
@ Parameter (property = "spring-boot.run.skip" , defaultValue = "false" )
@@ -206,9 +224,10 @@ private String determineMainClass() throws MojoExecutionException {
206
224
}
207
225
208
226
/**
209
- * Returns the directories that contain the application's classes and resources. When
210
- * the application's main class has not been configured, each directory is searched in
211
- * turn for an appropriate main class.
227
+ * Returns the directories that contain the application's classes and resources.
228
+ * When the application's main class has not been configured, each directory is
229
+ * searched in turn for an appropriate main class.
230
+ *
212
231
* @return the directories that contain the application's classes and resources
213
232
* @since 3.1.0
214
233
*/
@@ -237,6 +256,7 @@ private void run(String startClassName) throws MojoExecutionException, MojoFailu
237
256
238
257
/**
239
258
* Run the application.
259
+ *
240
260
* @param processExecutor the {@link JavaProcessExecutor} to use
241
261
* @param workingDirectory the working directory of the forked JVM
242
262
* @param args the arguments (JVM arguments and application arguments)
@@ -250,6 +270,7 @@ protected abstract void run(JavaProcessExecutor processExecutor, File workingDir
250
270
251
271
/**
252
272
* Resolve the application arguments to use.
273
+ *
253
274
* @return a {@link RunArguments} defining the application arguments
254
275
*/
255
276
protected RunArguments resolveApplicationArguments () {
@@ -261,6 +282,7 @@ protected RunArguments resolveApplicationArguments() {
261
282
262
283
/**
263
284
* Resolve the environment variables to use.
285
+ *
264
286
* @return an {@link EnvVariables} defining the environment variables
265
287
*/
266
288
protected EnvVariables resolveEnvVariables () {
@@ -281,15 +303,15 @@ private Map<String, String> determineEnvironmentVariables() {
281
303
282
304
/**
283
305
* Resolve the JVM arguments to use.
306
+ *
284
307
* @return a {@link RunArguments} defining the JVM arguments
285
308
*/
286
309
protected RunArguments resolveJvmArguments () {
287
310
StringBuilder stringBuilder = new StringBuilder ();
288
311
if (this .systemPropertyVariables != null ) {
289
- stringBuilder .append (this .systemPropertyVariables .entrySet ()
290
- .stream ()
291
- .map ((e ) -> SystemPropertyFormatter .format (e .getKey (), e .getValue ()))
292
- .collect (Collectors .joining (" " )));
312
+ stringBuilder .append (this .systemPropertyVariables .entrySet ().stream ()
313
+ .map ((e ) -> SystemPropertyFormatter .format (e .getKey (), e .getValue ()))
314
+ .collect (Collectors .joining (" " )));
293
315
}
294
316
if (this .jvmArguments != null ) {
295
317
stringBuilder .append (" " ).append (this .jvmArguments );
@@ -333,14 +355,12 @@ private void addActiveProfileArgument(RunArguments arguments) {
333
355
334
356
private void addClasspath (List <String > args ) throws MojoExecutionException {
335
357
try {
336
- Classpath classpath = ClasspathBuilder . forURLs (getClassPathUrls ()). build ( );
358
+ ClassPath classpath = ClassPath . of (getClassPathUrls ());
337
359
if (getLog ().isDebugEnabled ()) {
338
360
getLog ().debug ("Classpath for forked process: " + classpath );
339
361
}
340
- args .add ("-cp" );
341
- args .add (classpath .argument ());
342
- }
343
- catch (Exception ex ) {
362
+ args .addAll (classpath .args (true ));
363
+ } catch (Exception ex ) {
344
364
throw new MojoExecutionException ("Could not build classpath" , ex );
345
365
}
346
366
}
@@ -353,8 +373,7 @@ protected URL[] getClassPathUrls() throws MojoExecutionException {
353
373
addProjectClasses (urls );
354
374
addDependencies (urls );
355
375
return urls .toArray (new URL [0 ]);
356
- }
357
- catch (IOException ex ) {
376
+ } catch (IOException ex ) {
358
377
throw new MojoExecutionException ("Unable to build classpath" , ex );
359
378
}
360
379
}
0 commit comments