Additional Classpath Elements
If you need to put more stuff in your classpath when Surefire executes (e.g some funky resources or a container specific JAR), we normally recommend you add it to your classpath as a regular project dependency (with scope
test
). Consider deploying shared JARs to a private remote repository for your organization.
In case this leads to dependency conflicts usually separating the test classes from the actual test execution into separate Maven modules is the recommended approach then.
But, if you must, you can use the
additionalClasspathElements
element to add custom resources/JARs to your test classpath at runtime (without affecting the test classpath used for compilation). The items will be treated as absolute file system paths, 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-surefire-plugin</artifactId>
<version>3.5.3</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>