From 625b40aa90b9dbc4e353ab1e5f307d92bc40500c Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Fri, 7 Feb 2020 14:35:42 -0600 Subject: [PATCH] Prefer arguments in POM over spring-boot.run.arguments This commit changes the order of precedence for the `arguments` property of the AbstractRunMojo so that values specified in the POM override values provided on the command line using `spring-boot.run.arguments`. This brings the `arguments` property in line with all other Mojo parameters. Fixes gh-20024 --- .../run-arguments-override/invoker.properties | 1 + .../src/it/run-arguments-override/pom.xml | 36 ++++++++++++++++++ .../main/java/org/test/SampleApplication.java | 38 +++++++++++++++++++ .../it/run-arguments-override/test.properties | 1 + .../it/run-arguments-override/verify.groovy | 2 + .../boot/maven/AbstractRunMojo.java | 4 +- 6 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/invoker.properties create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/pom.xml create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/src/main/java/org/test/SampleApplication.java create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/test.properties create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/verify.groovy diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/invoker.properties b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/invoker.properties new file mode 100644 index 0000000000..9225c36f9e --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/invoker.properties @@ -0,0 +1 @@ +invoker.systemPropertiesFile=test.properties diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/pom.xml new file mode 100644 index 0000000000..90caf9ec8d --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + org.springframework.boot.maven.it + run-arguments-override + 0.0.1.BUILD-SNAPSHOT + + UTF-8 + @java.version@ + @java.version@ + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + package + + run + + + + --management.endpoints.web.exposure.include=prometheus,info + --spring.profiles.active=foo,bar + + + + + + + + diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/src/main/java/org/test/SampleApplication.java new file mode 100644 index 0000000000..60261a5d32 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/src/main/java/org/test/SampleApplication.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.test; + +import java.util.Arrays; + +public class SampleApplication { + + public static void main(String[] args) { + if (args.length < 2) { + throw new IllegalArgumentException("Missing arguments " + Arrays.toString(args) + ""); + } + if (!args[0].startsWith("--management.endpoints.web.exposure.include=")) { + throw new IllegalArgumentException("Invalid argument " + args[0]); + } + if (!args[1].startsWith("--spring.profiles.active=")) { + throw new IllegalArgumentException("Invalid argument " + args[1]); + } + String endpoints = args[0].split("=")[1]; + String profile = args[1].split("=")[1]; + System.out.println("I haz been run with profile(s) '" + profile + "' and endpoint(s) '" + endpoints + "'"); + } + +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/test.properties b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/test.properties new file mode 100644 index 0000000000..f059048195 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/test.properties @@ -0,0 +1 @@ +spring-boot.run.arguments=--management.endpoints.web.exposure.include=health,metrics --spring.profiles.active=test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/verify.groovy b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/verify.groovy new file mode 100644 index 0000000000..2a7cc17ab5 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-override/verify.groovy @@ -0,0 +1,2 @@ +def file = new File(basedir, "build.log") +return file.text.contains("I haz been run with profile(s) 'foo,bar' and endpoint(s) 'prometheus,info'") diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java index 98f53deac0..9aac40c5d6 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java @@ -319,8 +319,8 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo { * @return a {@link RunArguments} defining the application arguments */ protected RunArguments resolveApplicationArguments() { - RunArguments runArguments = (this.commandlineArguments != null) ? new RunArguments(this.commandlineArguments) - : new RunArguments(this.arguments); + RunArguments runArguments = (this.arguments != null) ? new RunArguments(this.arguments) + : new RunArguments(this.commandlineArguments); addActiveProfileArgument(runArguments); return runArguments; }