I've tested the new commit. It appears to be working for my purposes - testing a packaged for distribution product rather than the project compiled classes. Thank you for implementing this feature!
I'm putting below a sample configuration just for a reference. I see that system dependencies can be excluded either by the "test" scope or with their group and artifact id. Also the build classes can be excluded by configuring a fake location for them and although looking hacky, this method seems reasonable to me.
<profile>
<id>product-test</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6-SNAPSHOT</version>
<configuration>
<classesDirectory>fakeClassesDirectory</classesDirectory>
fakeTestClassesDirectory</testClassesDirectory -->
<classpathDependencyScopeExclude>runtime</classpathDependencyScopeExclude>
<classpathDependencyExcludes>
<exclude>org.apache.commons:*</exclude>
<exclude>testGrp:testId</exclude>
</classpathDependencyExcludes>
<additionalClasspathElements>
<additionalClasspathElement>/path/to/product/installation/artifact1.jar</additionalClasspathElement>
<additionalClasspathElement>/path/to/product/installation/artifact2.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Then tester should look at the mvn -Pproduct-test -X output (search for "Test Classpath")to verify classpath is what's expected. btw it will become more convenient once MNG-2570 is resolved and debug logging only from the SurefirePlugin class can be enabled through CLI rather than full debug of everything.
Forgot to describe a usecase. Say you are developing a library and you have an optional dependency to another library. Depending on whether this optional library is used at runtime your own library behaves differently. In this scenario I would like to have two test sets. One where the tests are run with the optional dependency on the classpath and one without. It is already possible two configure two executions of the surefire plugin, but I cannot remove a dependency. Basically optional dependencies should be removable via some excludes configuration.