diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/pom.xml b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/pom.xml
new file mode 100644
index 0000000000..dc8665151f
--- /dev/null
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/pom.xml
@@ -0,0 +1,35 @@
+
+
+ 4.0.0
+ org.springframework.boot.maven.it
+ run-profiles
+ 0.0.1.BUILD-SNAPSHOT
+
+ UTF-8
+
+
+
+
+ @project.groupId@
+ @project.artifactId@
+ @project.version@
+
+
+ package
+
+ run
+
+
+ true
+
+ foo
+ bar
+
+
+
+
+
+
+
+
diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/src/main/java/org/test/SampleApplication.java b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/src/main/java/org/test/SampleApplication.java
new file mode 100644
index 0000000000..5e19ea31cd
--- /dev/null
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/src/main/java/org/test/SampleApplication.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2012-2014 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
+ *
+ * http://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 < 1) {
+ throw new IllegalArgumentException("Missing active profile argument " + Arrays.toString(args) + "");
+ }
+ String argument = args[0];
+ if (!argument.startsWith("--spring.profiles.active=")) {
+ throw new IllegalArgumentException("Invalid argument " + argument);
+ }
+ int index = args[0].indexOf("=");
+ String profile = argument.substring(index + 1, argument.length());
+ System.out.println("I haz been run with profile(s) '" + profile + "'");
+ }
+
+}
diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/verify.groovy b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/verify.groovy
new file mode 100644
index 0000000000..c9cb44bb05
--- /dev/null
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles-fork/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'")
\ No newline at end of file
diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles/pom.xml b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles/pom.xml
new file mode 100644
index 0000000000..f780e91b1f
--- /dev/null
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles/pom.xml
@@ -0,0 +1,34 @@
+
+
+ 4.0.0
+ org.springframework.boot.maven.it
+ run-profiles
+ 0.0.1.BUILD-SNAPSHOT
+
+ UTF-8
+
+
+
+
+ @project.groupId@
+ @project.artifactId@
+ @project.version@
+
+
+ package
+
+ run
+
+
+
+ foo
+ bar
+
+
+
+
+
+
+
+
diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles/src/main/java/org/test/SampleApplication.java b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles/src/main/java/org/test/SampleApplication.java
new file mode 100644
index 0000000000..5e19ea31cd
--- /dev/null
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles/src/main/java/org/test/SampleApplication.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2012-2014 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
+ *
+ * http://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 < 1) {
+ throw new IllegalArgumentException("Missing active profile argument " + Arrays.toString(args) + "");
+ }
+ String argument = args[0];
+ if (!argument.startsWith("--spring.profiles.active=")) {
+ throw new IllegalArgumentException("Invalid argument " + argument);
+ }
+ int index = args[0].indexOf("=");
+ String profile = argument.substring(index + 1, argument.length());
+ System.out.println("I haz been run with profile(s) '" + profile + "'");
+ }
+
+}
diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles/verify.groovy b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles/verify.groovy
new file mode 100644
index 0000000000..c9cb44bb05
--- /dev/null
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-profiles/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'")
\ No newline at end of file
diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java
index e621ebc7a2..860f559083 100644
--- a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java
@@ -53,6 +53,8 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
private static final String SPRING_LOADED_AGENT_CLASSNAME = "org.springsource.loaded.agent.SpringLoadedAgent";
+ private static final String ACTIVE_PROFILES_PROPERTY = "spring.profiles.active";
+
/**
* The Maven project.
* @since 1.0
@@ -100,6 +102,15 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
@Parameter(property = "run.arguments")
private String[] arguments;
+ /**
+ * The spring profiles to activate. Convenience shortcut of specifying the
+ * 'spring.profiles.active' argument. On command line use commas to separate
+ * multiple profiles.
+ * @since 1.3
+ */
+ @Parameter(property = "run.profiles")
+ private String[] profiles;
+
/**
* The name of the main class. If not specified the first compiled class found that
* contains a 'main' method will be used.
@@ -239,7 +250,9 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
* @return a {@link RunArguments} defining the application arguments
*/
protected RunArguments resolveApplicationArguments() {
- return new RunArguments(this.arguments);
+ RunArguments runArguments = new RunArguments(this.arguments);
+ addActiveProfileArgument(runArguments);
+ return runArguments;
}
private void addArgs(List args) {
@@ -274,6 +287,21 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
}
}
+ private void addActiveProfileArgument(RunArguments arguments) {
+ if (this.profiles.length > 0) {
+ StringBuilder sb = new StringBuilder("--")
+ .append(ACTIVE_PROFILES_PROPERTY).append("=");
+ for (int i = 0; i < this.profiles.length; i++) {
+ sb.append(this.profiles[i]);
+ if (i < this.profiles.length - 1) {
+ sb.append(",");
+ }
+ }
+ arguments.getArgs().addFirst(sb.toString());
+ logArguments("Active profile(s): ", this.profiles);
+ }
+ }
+
private void addClasspath(List args) throws MojoExecutionException {
try {
StringBuilder classpath = new StringBuilder();
diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/examples/run-profiles.apt.vm b/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/examples/run-profiles.apt.vm
new file mode 100644
index 0000000000..1562e9ac89
--- /dev/null
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/examples/run-profiles.apt.vm
@@ -0,0 +1,47 @@
+ -----
+ Specify active profiles
+ -----
+ Stephane Nicoll
+ -----
+ 2014-07-07
+ -----
+
+ The active profiles to use for a particular application can be specified using the <<>>
+ argument. The following configuration enables the foo and bar profiles:
+
+---
+
+ ...
+
+ ...
+
+ ...
+
+ ${project.groupId}
+ ${project.artifactId}
+ ${project.version}
+
+
+ foo
+ bar
+
+
+ ...
+
+ ...
+
+ ...
+
+ ...
+
+---
+
+ The profiles to enable can be specified on the command line as well, make sure to separate them with
+ a comma, that is:
+
+---
+mvn spring-boot:run -Drun.profiles=foo,bar
+---
+
+
+
diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/index.apt b/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/index.apt
index 1c041ec32e..d7a7e99595 100644
--- a/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/index.apt
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/index.apt
@@ -48,6 +48,8 @@ Spring Boot Maven Plugin
* {{{./examples/it-random-port.html}Random port for integration tests}}
+ * {{{./examples/run-profiles.html}Specify active profiles}}
+
[]
diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/usage.apt.vm b/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/usage.apt.vm
index e6aa2da0b4..162b5f418d 100644
--- a/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/usage.apt.vm
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/usage.apt.vm
@@ -116,7 +116,8 @@ mvn spring-boot:run
If you need to specify some JVM arguments (i.e. for debugging purposes), you can use
the <<>> parameter, see {{{./examples/run-debug.html}Debug the application}}
- for more details.
+ for more details. As a convenience, the profiles to enable are handed by a specific
+ property (<<>>), see {{{./examples/run-profiles.html}Specify active profiles}}.
By default, any <> folder will be added to the application classpath
when you run the application and any duplicate found in <> will be
diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/site/site.xml b/spring-boot-tools/spring-boot-maven-plugin/src/site/site.xml
index b8c6591f21..76499d51a7 100644
--- a/spring-boot-tools/spring-boot-maven-plugin/src/site/site.xml
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/site/site.xml
@@ -11,6 +11,7 @@
+