How do I exclude a dependency in provided scope when running in Maven test scope?

北城以北 提交于 2019-12-24 05:06:35

问题


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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/12314397/how-do-i-exclude-a-dependency-in-provided-scope-when-running-in-maven-test-scope

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!