The Surefire plugin builds the test classpath in the following order:
Notice that loading JAR file is preferable over the output classes directory in the maven-failsafe-plugin.
If you need to put more stuff in your classpath when Failsafe executes (e.g some funky resources or a container specific JAR), we normally recommend you add it to your classpath as a dependency. Consider deploying shared JARs to a private remote repository for your organization.
But, if you must, you can use the additionalClasspathElements element to add custom resources/JARs to your classpath. This will be treated as an absolute file system path, so you may want use ${basedir} or another property combined with a relative path. Note that additional classpath elements are added to the end of the classpath, so you cannot use these to override project dependencies or resources.
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.19</version> <configuration> <additionalClasspathElements> <additionalClasspathElement>path/to/additional/resources</additionalClasspathElement> <additionalClasspathElement>path/to/additional/jar</additionalClasspathElement> <additionalClasspathElement>path/to/csv/jar1, path/to/csv/jar2</additionalClasspathElement> </additionalClasspathElements> </configuration> </plugin> </plugins> </build> [...] </project>
Dependencies can be removed from the test classpath using the parameters classpathDependencyExcludes and classpathDependencyScopeExclude. A list of specific dependencies can be removed from the classpath by specifying the groupId:artifactId to be removed.
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.19</version> <configuration> <classpathDependencyExcludes> <classpathDependencyExcludes>org.apache.commons:commons-email</classpathDependencyExcludes> </classpathDependencyExcludes> </configuration> </plugin> </plugins> </build> [...] </project>
Dependencies under a certain scope can be removed from the classpath using classpathDependencyScopeExclude. The valid values for the dependency scope exclude are defined by org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter.
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.19</version> <configuration> <classpathDependencyScopeExclude>runtime</classpathDependencyScopeExclude> </configuration> </plugin> </plugins> </build> [...] </project>