diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/run-use-test-classpath/pom.xml b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-use-test-classpath/pom.xml
new file mode 100644
index 0000000000..5084c8041f
--- /dev/null
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-use-test-classpath/pom.xml
@@ -0,0 +1,39 @@
+
+
+ 4.0.0
+ org.springframework.boot.maven.it
+ run-use-test-classpath
+ 0.0.1.BUILD-SNAPSHOT
+
+ UTF-8
+
+
+
+
+ @project.groupId@
+ @project.artifactId@
+ @project.version@
+
+
+ package
+
+ run
+
+
+ true
+
+
+
+
+
+
+
+
+ org.springframework
+ spring-context
+ @spring.version@
+ test
+
+
+
diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/run-use-test-classpath/src/main/java/org/test/SampleApplication.java b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-use-test-classpath/src/main/java/org/test/SampleApplication.java
new file mode 100644
index 0000000000..bcb7456c34
--- /dev/null
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-use-test-classpath/src/main/java/org/test/SampleApplication.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2012-2015 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;
+
+public class SampleApplication {
+
+ public static void main(String[] args) {
+
+ Class> appContext = null;
+ try {
+ appContext = Class.forName("org.springframework.context.ApplicationContext");
+ }
+ catch (ClassNotFoundException e) {
+ throw new IllegalStateException("Test dependencies not added to classpath", e);
+ }
+ System.out.println("I haz been run");
+ }
+
+}
diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/run-use-test-classpath/verify.groovy b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-use-test-classpath/verify.groovy
new file mode 100644
index 0000000000..841c4a97de
--- /dev/null
+++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/run-use-test-classpath/verify.groovy
@@ -0,0 +1,3 @@
+def file = new File(basedir, "build.log")
+return file.text.contains("I haz been run")
+
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 0eac1e8714..e03f1d9628 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
@@ -36,6 +36,7 @@ import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.artifact.filter.collection.AbstractArtifactFeatureFilter;
import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
+
import org.springframework.boot.loader.tools.FileUtils;
import org.springframework.boot.loader.tools.MainClassFinder;
@@ -45,6 +46,7 @@ import org.springframework.boot.loader.tools.MainClassFinder;
* @author Phillip Webb
* @author Stephane Nicoll
* @author David Liu
+ * @author Daniel Young
* @see RunMojo
* @see StartMojo
*/
@@ -131,6 +133,13 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
@Parameter(property = "fork")
private Boolean fork;
+ /**
+ * Flag to include the test classpath when running.
+ * @since 1.3
+ */
+ @Parameter(property = "useTestClasspath", defaultValue = "false")
+ private Boolean useTestClasspath;
+
/**
* Specify if the application process should be forked.
* @return {@code true} if the application process should be forked
@@ -340,7 +349,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
private void addDependencies(List urls) throws MalformedURLException,
MojoExecutionException {
- FilterArtifacts filters = getFilters(new TestArtifactFilter());
+ FilterArtifacts filters = this.useTestClasspath ? getFilters() : getFilters(new TestArtifactFilter());
Set artifacts = filterDependencies(this.project.getArtifacts(), filters);
for (Artifact artifact : artifacts) {
if (artifact.getFile() != null) {
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 9d252b44c2..e16b7bc8ec 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
@@ -151,6 +151,11 @@ mvn spring-boot:run
in such a way that any dependency that is excluded in the plugin's configuration gets excluded
from the classpath as well. See {{{./examples/exclude-dependency.html}Exclude a dependency}} for
more details.
+
+ Sometimes it is useful to include test dependencies when running the application. For example,
+ if you want to run your application in a test mode that uses stub classes. If you wish to do this,
+ you can set the <<>> parameter to true. Note that this is only applied when you
+ run an application: the <<>> goal will not add test dependencies to the resulting JAR/WAR.
* Working with integration tests