3939import org .apache .maven .toolchain .ToolchainManager ;
4040
4141import org .springframework .boot .loader .tools .FileUtils ;
42- import org .springframework .boot .maven .ClasspathBuilder .Classpath ;
4342
4443/**
4544 * Base class to run a Spring Boot application.
@@ -58,132 +57,151 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
5857
5958 /**
6059 * The Maven project.
60+ *
6161 * @since 1.0.0
6262 */
6363 @ Parameter (defaultValue = "${project}" , readonly = true , required = true )
6464 private MavenProject project ;
6565
6666 /**
6767 * The current Maven session. This is used for toolchain manager API calls.
68+ *
6869 * @since 2.3.0
6970 */
7071 @ Parameter (defaultValue = "${session}" , readonly = true )
7172 private MavenSession session ;
7273
7374 /**
7475 * The toolchain manager to use to locate a custom JDK.
76+ *
7577 * @since 2.3.0
7678 */
7779 @ Component
7880 private ToolchainManager toolchainManager ;
7981
8082 /**
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+ *
8690 * @since 1.0.0
8791 */
8892 @ Parameter (property = "spring-boot.run.addResources" , defaultValue = "false" )
8993 private boolean addResources = false ;
9094
9195 /**
9296 * Path to agent jars.
97+ *
9398 * @since 2.2.0
9499 */
95100 @ Parameter (property = "spring-boot.run.agents" )
96101 private File [] agents ;
97102
98103 /**
99104 * Flag to say that the agent requires -noverify.
105+ *
100106 * @since 1.0.0
101107 */
102108 @ Parameter (property = "spring-boot.run.noverify" )
103109 private boolean noverify = false ;
104110
105111 /**
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+ *
108115 * @since 1.5.0
109116 */
110117 @ Parameter (property = "spring-boot.run.workingDirectory" )
111118 private File workingDirectory ;
112119
113120 /**
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+ *
116125 * @since 1.1.0
117126 */
118127 @ Parameter (property = "spring-boot.run.jvmArguments" )
119128 private String jvmArguments ;
120129
121130 /**
122131 * List of JVM system properties to pass to the process.
132+ *
123133 * @since 2.1.0
124134 */
125135 @ Parameter
126136 private Map <String , String > systemPropertyVariables ;
127137
128138 /**
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+ *
131142 * @since 2.1.0
132143 */
133144 @ Parameter
134145 private Map <String , String > environmentVariables ;
135146
136147 /**
137148 * Arguments that should be passed to the application.
149+ *
138150 * @since 1.0.0
139151 */
140152 @ Parameter
141153 private String [] arguments ;
142154
143155 /**
144156 * 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+ *
147160 * @since 2.2.3
148161 */
149162 @ Parameter (property = "spring-boot.run.arguments" )
150163 private String commandlineArguments ;
151164
152165 /**
153166 * 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+ *
156170 * @since 1.3.0
157171 */
158172 @ Parameter (property = "spring-boot.run.profiles" )
159173 private String [] profiles ;
160174
161175 /**
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+ *
164179 * @since 1.0.0
165180 */
166181 @ Parameter (property = "spring-boot.run.main-class" )
167182 private String mainClass ;
168183
169184 /**
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+ *
172188 * @since 3.2.0
173189 */
174190 @ Parameter (property = "spring-boot.run.additional-classpath-elements" )
175191 private String [] additionalClasspathElements ;
176192
177193 /**
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+ *
180197 * @since 1.0.0
181198 */
182199 @ Parameter (defaultValue = "${project.build.outputDirectory}" , required = true )
183200 private File classesDirectory ;
184201
185202 /**
186203 * Skip the execution.
204+ *
187205 * @since 1.3.2
188206 */
189207 @ Parameter (property = "spring-boot.run.skip" , defaultValue = "false" )
@@ -206,9 +224,10 @@ private String determineMainClass() throws MojoExecutionException {
206224 }
207225
208226 /**
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+ *
212231 * @return the directories that contain the application's classes and resources
213232 * @since 3.1.0
214233 */
@@ -237,6 +256,7 @@ private void run(String startClassName) throws MojoExecutionException, MojoFailu
237256
238257 /**
239258 * Run the application.
259+ *
240260 * @param processExecutor the {@link JavaProcessExecutor} to use
241261 * @param workingDirectory the working directory of the forked JVM
242262 * @param args the arguments (JVM arguments and application arguments)
@@ -250,6 +270,7 @@ protected abstract void run(JavaProcessExecutor processExecutor, File workingDir
250270
251271 /**
252272 * Resolve the application arguments to use.
273+ *
253274 * @return a {@link RunArguments} defining the application arguments
254275 */
255276 protected RunArguments resolveApplicationArguments () {
@@ -261,6 +282,7 @@ protected RunArguments resolveApplicationArguments() {
261282
262283 /**
263284 * Resolve the environment variables to use.
285+ *
264286 * @return an {@link EnvVariables} defining the environment variables
265287 */
266288 protected EnvVariables resolveEnvVariables () {
@@ -281,15 +303,15 @@ private Map<String, String> determineEnvironmentVariables() {
281303
282304 /**
283305 * Resolve the JVM arguments to use.
306+ *
284307 * @return a {@link RunArguments} defining the JVM arguments
285308 */
286309 protected RunArguments resolveJvmArguments () {
287310 StringBuilder stringBuilder = new StringBuilder ();
288311 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 (" " )));
293315 }
294316 if (this .jvmArguments != null ) {
295317 stringBuilder .append (" " ).append (this .jvmArguments );
@@ -333,14 +355,12 @@ private void addActiveProfileArgument(RunArguments arguments) {
333355
334356 private void addClasspath (List <String > args ) throws MojoExecutionException {
335357 try {
336- Classpath classpath = ClasspathBuilder . forURLs (getClassPathUrls ()). build ( );
358+ ClassPath classpath = ClassPath . of (getClassPathUrls ());
337359 if (getLog ().isDebugEnabled ()) {
338360 getLog ().debug ("Classpath for forked process: " + classpath );
339361 }
340- args .add ("-cp" );
341- args .add (classpath .argument ());
342- }
343- catch (Exception ex ) {
362+ args .addAll (classpath .args (true ));
363+ } catch (Exception ex ) {
344364 throw new MojoExecutionException ("Could not build classpath" , ex );
345365 }
346366 }
@@ -353,8 +373,7 @@ protected URL[] getClassPathUrls() throws MojoExecutionException {
353373 addProjectClasses (urls );
354374 addDependencies (urls );
355375 return urls .toArray (new URL [0 ]);
356- }
357- catch (IOException ex ) {
376+ } catch (IOException ex ) {
358377 throw new MojoExecutionException ("Unable to build classpath" , ex );
359378 }
360379 }
0 commit comments