Maven: How do I include a dependency in test phase and exclude it in integration-test phase?

空扰寡人 提交于 2020-01-15 03:29:08

问题


I'm using Maven 3.0.3.
Is it possible to include a dependency for my test phase only, and then another dependency for my integration-phase only? When these two dependencies are included together

<dependency> 
    <groupId>com.google.gwt</groupId> 
    <artifactId>gwt-dev</artifactId> 
    <version>${gwtVersion}</version> 
    <scope>test</scope> 
</dependency> 
... 
<dependency> 
    <groupId>org.seleniumhq.selenium</groupId> 
    <artifactId>selenium-java</artifactId> 
    <version>2.13.0</version> 
    <scope>test</scope> 
</dependency> 

I get a java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init> error when running my Selenium integration tests. When the GWT dependency is excluded, the Selenium tests run. I still need the GWT dependency for the test phase, tho.


回答1:


With respect to the answers given, the one I liked best was simply adding a "classpathDependencyExcludes" to my failsafe-plugin execution ...

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.10</version>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                    <configuration>
                        <includes>
                            <include>**/integration/**</include>
                        </includes>
                        <systemPropertyVariables>
                            <tomcat.port>${tomcat.servlet.port}</tomcat.port>
                            <project.artifactId>${project.artifactId}</project.artifactId>
                        </systemPropertyVariables>
                        <classpathDependencyExcludes>
                            <classpathDependencyExcludes>com.google.gwt:gwt-dev</classpathDependencyExcludes>
                        </classpathDependencyExcludes>
                    </configuration>
                </execution>
            </executions>
        </plugin>

That ensured that the problematic dependency (in this case gwt-dev), would not appear when running the integration-test phase.




回答2:


Use profiles. A profile allows you to add dependencies depending on the arguments of the -P command line option.




回答3:


Different dependency sets in Maven profiles are the only way to achieve this, since the "test" scope encloses both "test" and "integration-test" phase.



来源:https://stackoverflow.com/questions/8232748/maven-how-do-i-include-a-dependency-in-test-phase-and-exclude-it-in-integration

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