Reputation: 2743
How do I exclude a dependency in provided scope when running in Maven test scope? I have an unusual use case where I need to exclude a particular provided implementation and replace it with another in the test cases. It seems that Maven tests always include other scopes as well but in my case I want to make some exception. How do I do this?
Upvotes: 3
Views: 1382
Reputation: 1510
I think, the simplest way to do this is to create 2 profiles for each dependency you want to use. You can activateByDefault the one with provided scope.
It may look like this :
<profiles>
<profile>
<id>providedDependency</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>[provided dependency information]</dependency>
</dependencies>
</profile>
<profile>
<id>testDependency</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>[test dependency information]</dependency>
</dependencies>
</profile>
</profiles>
When passing into test mode, unactivate the provided dependency and activate the other
mvn test -P!providedDependency,testDependency
Upvotes: 2
Reputation: 533820
There are situations where you need to run your tests in a different module. That may be what you need here. It allows your tests to use different dependencies, properties and version of Java etc.
Upvotes: 2