Maven:如何在测试阶段包括依赖项,而在集成测试阶段将其排除在外? [英] Maven: How do I include a dependency in test phase and exclude it in integration-test phase?

查看:86
本文介绍了Maven:如何在测试阶段包括依赖项,而在集成测试阶段将其排除在外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Maven 3.0.3.
是否可以仅在我的测试阶段包含一个依赖项,然后在我的集成阶段仅包含另一个依赖项?当这两个依赖项一起包含时

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> 

运行Selenium集成测试时出现java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init>错误.当排除GWT依赖关系时,将运行Selenium测试.在测试阶段,我仍然需要GWT依赖项.

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.

推荐答案

对于给出的答案,我最喜欢的答案是在我的故障安全插件执行中简单地添加一个"classpathDependencyExcludes" ...

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>

这确保了在运行集成测试阶段时不会出现有问题的依赖关系(在本例中为gwt-dev).

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

这篇关于Maven:如何在测试阶段包括依赖项,而在集成测试阶段将其排除在外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆