diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/MavenBuild.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/MavenBuild.java index ad5485e8d5..599f99cb5b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/MavenBuild.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/MavenBuild.java @@ -46,6 +46,7 @@ import org.apache.maven.shared.invoker.DefaultInvoker; import org.apache.maven.shared.invoker.InvocationRequest; import org.apache.maven.shared.invoker.InvocationResult; import org.apache.maven.shared.invoker.Invoker; +import org.apache.maven.shared.invoker.InvokerLogger; import org.apache.maven.shared.invoker.MavenInvocationException; import static org.assertj.core.api.Assertions.assertThat; @@ -184,6 +185,7 @@ class MavenBuild { buildLog.flush(); }); try { + invoker.getLogger().setThreshold(InvokerLogger.DEBUG); InvocationResult result = invoker.execute(request); assertThat(result.getExitCode()).as(contentOf(buildLogFile)).isEqualTo(expectedExitCode); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/RunIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/RunIntegrationTests.java index 9c20e96fa6..0b83d8b376 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/RunIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/RunIntegrationTests.java @@ -71,7 +71,7 @@ class RunIntegrationTests { } @TestTemplate - void whenSystemPropertiesAreConfiguredTheyAreAvailableToTheApplication(MavenBuild mavenBuild) { + void whenSystemPropertiesAndJvmArgumentsAreConfiguredTheyAreAvailableToTheApplication(MavenBuild mavenBuild) { mavenBuild.project("run-jvm-system-props").goals("spring-boot:run") .execute((project) -> assertThat(buildLog(project)).contains("I haz been run")); } @@ -82,6 +82,20 @@ class RunIntegrationTests { .execute((project) -> assertThat(buildLog(project)).contains("I haz been run")); } + @TestTemplate + void whenCommandLineSpecifiesJvmArgumentsTheyAreAvailableToTheApplication(MavenBuild mavenBuild) { + mavenBuild.project("run-jvmargs-commandline").goals("spring-boot:run") + .systemProperty("spring-boot.run.jvmArguments", "\"-Dfoo=value1\" \"-Dbar=value2\"") + .execute((project) -> assertThat(buildLog(project)).contains("I haz been run")); + } + + @TestTemplate + void whenPomAndCommandLineSpecifyJvmArgumentsThenPomOverrides(MavenBuild mavenBuild) { + mavenBuild.project("run-jvmargs").goals("spring-boot:run") + .systemProperty("spring-boot.run.jvmArguments", "\"-Dfoo=value-from-cmd\"") + .execute((project) -> assertThat(buildLog(project)).contains("I haz been run")); + } + @TestTemplate void whenProfilesAreConfiguredTheyArePassedToTheApplication(MavenBuild mavenBuild) { mavenBuild.project("run-profiles").goals("spring-boot:run", "-X").execute( @@ -102,8 +116,8 @@ class RunIntegrationTests { @TestTemplate void whenAWorkingDirectoryIsConfiguredTheApplicationIsRunFromThatDirectory(MavenBuild mavenBuild) { - mavenBuild.project("run-working-directory").goals("spring-boot:run") - .execute((project) -> assertThat(buildLog(project)).contains("I haz been run")); + mavenBuild.project("run-working-directory").goals("spring-boot:run").execute( + (project) -> assertThat(buildLog(project)).containsPattern("I haz been run from.*/src/main/java")); } @TestTemplate @@ -129,6 +143,15 @@ class RunIntegrationTests { "I haz been run with profile(s) 'foo,bar' and endpoint(s) 'prometheus,info,health,metrics'")); } + @TestTemplate + void whenPomAndCommandLineSpecifyRunArgumentsThenPomOverrides(MavenBuild mavenBuild) { + mavenBuild.project("run-arguments").goals("spring-boot:run") + .systemProperty("spring-boot.run.arguments", + "--management.endpoints.web.exposure.include=one,two,three --spring.profiles.active=test") + .execute((project) -> assertThat(buildLog(project)) + .contains("I haz been run with profile(s) 'foo,bar' and endpoint(s) 'prometheus,info'")); + } + private String buildLog(File project) { return contentOf(new File(project, "target/build.log")); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/run-jvmargs-commandline/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/run-jvmargs-commandline/pom.xml new file mode 100644 index 0000000000..bd5f47bec3 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/run-jvmargs-commandline/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + org.springframework.boot.maven.it + run-jvmargs-commandline + 0.0.1.BUILD-SNAPSHOT + + UTF-8 + @java.version@ + @java.version@ + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/run-jvmargs-commandline/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/run-jvmargs-commandline/src/main/java/org/test/SampleApplication.java new file mode 100644 index 0000000000..75bd969535 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/run-jvmargs-commandline/src/main/java/org/test/SampleApplication.java @@ -0,0 +1,33 @@ +/* + * 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; + +public class SampleApplication { + + public static void main(String[] args) { + String foo = System.getProperty("foo"); + if (!"value1".equals(foo)) { + throw new IllegalStateException("foo system property mismatch (got [" + foo + "]"); + } + String bar = System.getProperty("bar"); + if (!"value2".equals(bar)) { + throw new IllegalStateException("bar system property mismatch (got [" + bar + "]"); + } + System.out.println("I haz been run"); + } + +} 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 68b572691b..fdae3fcfde 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 @@ -317,8 +317,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; }