Skip to content

Commit a2b2b46

Browse files
committed
Merge branch '2.2.x'
Closes gh-19463
2 parents 2c1e81a + 83e594a commit a2b2b46

File tree

9 files changed

+162
-5
lines changed

9 files changed

+162
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.systemPropertiesFile=test.properties
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.springframework.boot.maven.it</groupId>
6+
<artifactId>run-arguments-commandline</artifactId>
7+
<version>0.0.1.BUILD-SNAPSHOT</version>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.source>@java.version@</maven.compiler.source>
11+
<maven.compiler.target>@java.version@</maven.compiler.target>
12+
</properties>
13+
<build>
14+
<plugins>
15+
<plugin>
16+
<groupId>@project.groupId@</groupId>
17+
<artifactId>@project.artifactId@</artifactId>
18+
<version>@project.version@</version>
19+
<executions>
20+
<execution>
21+
<phase>package</phase>
22+
<goals>
23+
<goal>run</goal>
24+
</goals>
25+
</execution>
26+
</executions>
27+
</plugin>
28+
</plugins>
29+
</build>
30+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.test;
18+
19+
import java.util.Arrays;
20+
21+
public class SampleApplication {
22+
23+
public static void main(String[] args) {
24+
if (args.length < 2) {
25+
throw new IllegalArgumentException("Missing arguments " + Arrays.toString(args) + "");
26+
}
27+
if (!args[0].startsWith("--management.endpoints.web.exposure.include=")) {
28+
throw new IllegalArgumentException("Invalid argument " + args[0]);
29+
}
30+
if (!args[1].startsWith("--spring.profiles.active=")) {
31+
throw new IllegalArgumentException("Invalid argument " + args[1]);
32+
}
33+
String endpoints = args[0].split("=")[1];
34+
String profile = args[1].split("=")[1];
35+
System.out.println("I haz been run with profile(s) '" + profile + "' and endpoint(s) '" + endpoints + "'");
36+
}
37+
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring-boot.run.arguments=--management.endpoints.web.exposure.include=prometheus,info,health,metrics --spring.profiles.active=foo,bar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def file = new File(basedir, "build.log")
2+
return file.text.contains("I haz been run with profile(s) 'foo,bar' and endpoint(s) 'prometheus,info,health,metrics'")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.springframework.boot.maven.it</groupId>
6+
<artifactId>run-arguments</artifactId>
7+
<version>0.0.1.BUILD-SNAPSHOT</version>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.source>@java.version@</maven.compiler.source>
11+
<maven.compiler.target>@java.version@</maven.compiler.target>
12+
</properties>
13+
<build>
14+
<plugins>
15+
<plugin>
16+
<groupId>@project.groupId@</groupId>
17+
<artifactId>@project.artifactId@</artifactId>
18+
<version>@project.version@</version>
19+
<executions>
20+
<execution>
21+
<phase>package</phase>
22+
<goals>
23+
<goal>run</goal>
24+
</goals>
25+
<configuration>
26+
<arguments>
27+
<argument>--management.endpoints.web.exposure.include=prometheus,info</argument>
28+
<argument>--spring.profiles.active=foo,bar</argument>
29+
</arguments>
30+
</configuration>
31+
</execution>
32+
</executions>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.test;
18+
19+
import java.util.Arrays;
20+
21+
public class SampleApplication {
22+
23+
public static void main(String[] args) {
24+
if (args.length < 2) {
25+
throw new IllegalArgumentException("Missing arguments " + Arrays.toString(args) + "");
26+
}
27+
if (!args[0].startsWith("--management.endpoints.web.exposure.include=")) {
28+
throw new IllegalArgumentException("Invalid argument " + args[0]);
29+
}
30+
if (!args[1].startsWith("--spring.profiles.active=")) {
31+
throw new IllegalArgumentException("Invalid argument " + args[1]);
32+
}
33+
String endpoints = args[0].split("=")[1];
34+
String profile = args[1].split("=")[1];
35+
System.out.println("I haz been run with profile(s) '" + profile + "' and endpoint(s) '" + endpoints + "'");
36+
}
37+
38+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def file = new File(basedir, "build.log")
2+
return file.text.contains("I haz been run with profile(s) 'foo,bar' and endpoint(s) 'prometheus,info'")

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,21 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
133133
private Map<String, String> environmentVariables;
134134

135135
/**
136-
* Arguments that should be passed to the application. On command line use commas to
137-
* separate multiple arguments.
136+
* Arguments that should be passed to the application.
138137
* @since 1.0.0
139138
*/
140-
@Parameter(property = "spring-boot.run.arguments")
139+
@Parameter
141140
private String[] arguments;
142141

142+
/**
143+
* Arguments from the command line that should be passed to the application. Use
144+
* spaces to separate multiple arguments and make sure to wrap multiple values between
145+
* quotes. When specified, takes precedence over {@link #arguments}.
146+
* @since 2.2.3
147+
*/
148+
@Parameter(property = "spring-boot.run.arguments", readonly = true)
149+
private String commandlineArguments;
150+
143151
/**
144152
* The spring profiles to activate. Convenience shortcut of specifying the
145153
* 'spring.profiles.active' argument. On command line use commas to separate multiple
@@ -311,7 +319,8 @@ protected abstract void runWithMavenJvm(String startClassName, String... argumen
311319
* @return a {@link RunArguments} defining the application arguments
312320
*/
313321
protected RunArguments resolveApplicationArguments() {
314-
RunArguments runArguments = new RunArguments(this.arguments);
322+
RunArguments runArguments = (this.commandlineArguments != null) ? new RunArguments(this.commandlineArguments)
323+
: new RunArguments(this.arguments);
315324
addActiveProfileArgument(runArguments);
316325
return runArguments;
317326
}
@@ -327,7 +336,7 @@ protected EnvVariables resolveEnvVariables() {
327336
private void addArgs(List<String> args) {
328337
RunArguments applicationArguments = resolveApplicationArguments();
329338
Collections.addAll(args, applicationArguments.asArray());
330-
logArguments("Application argument(s): ", this.arguments);
339+
logArguments("Application argument(s): ", applicationArguments.asArray());
331340
}
332341

333342
private Map<String, String> determineEnvironmentVariables() {

0 commit comments

Comments
 (0)