我正在使用Maven 3.0.3。是否可以仅在我的测试阶段包含一个依赖项,然后在我的集成阶段仅包含另一个依赖项?当这两个依赖项一起包含时
<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依赖项,等等。
关于给出的答案,我最喜欢的是在我的故障安全插件执行中简单地添加一个“ classpathDependencyExcludes” ...
<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)。
使用profiles。概要文件允许您根据-P
命令行选项的参数添加依赖项。
Maven概要文件中的不同依赖集是实现此目的的唯一方法,因为“测试” 作用域包含“测试”和“集成测试” 阶段。
我建议有一个带有测试用例的单独项目