我们在POM文件中有以下配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
这可确保在测试阶段不执行测试。测试仅在集成测试阶段执行。
但是,当我们准备发布(发布:准备)时,maven会在测试阶段执行测试。这导致我们的构建失败,因为我们的测试只能在Integration测试阶段运行(我们使用tomcat-maven插件在执行测试之前部署打包的war)。
我知道我们可以通过传递参数(-DskipTests等)来跳过测试。我们不想跳过任何测试,我们只想要发布:准备执行就像任何其他maven目标一样。
非常感谢任何建议/帮助。
答案 0 :(得分:2)
将您的集成测试添加到默认情况下未处于活动状态的单独配置文件中。添加触发规则或其他内容。然后根据需要使用集成测试调用构建。例如,在你的CI(Jenkins / Hudson,TeamCity,Bamboo等)上触发了个人资料。
您目前面临的问题是您没有在两种类型的测试之间进行分离以及何时应该运行它们。您已经简单地定义了您希望它们执行的阶段。这不足以让Maven的执行上下文知道您想要做什么,并且它也会在发布期间调用它们。
答案 1 :(得分:2)
尝试使用更通用的方法在maven-surefire-plugin
阶段完全禁用test
。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<!-- Disable the default-test by putting it in phase none -->
<phase>none</phase>
</execution>
<execution>
<!-- Enable the test during integration-test phase -->
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
修改强>
这是我使用上面配置的surefire插件的mvn release:prepare
的干运行输出:
C:\Users\maba\Development\svn\local\stackoverflow\Q12840869>mvn release:prepare -DdryRun [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Q12840869-1.0-SNAPSHOT 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-release-plugin:2.0:prepare (default-cli) @ Q12840869 --- [INFO] Resuming release from phase 'scm-check-modifications' [INFO] Verifying that there are no local modifications... [INFO] Executing: cmd.exe /X /C "svn --non-interactive status" [INFO] Working directory: C:\Users\maba\Development\svn\local\stackoverflow\Q12840869 [INFO] Checking dependencies and plugins for snapshots ... What is the release version for "Q12840869-1.0-SNAPSHOT"? (com.stackoverflow:Q12840869) 1.0: : What is SCM release tag or label for "Q12840869-1.0-SNAPSHOT"? (com.stackoverflow:Q12840869) Q12840869-1.0: : What is the new development version for "Q12840869-1.0-SNAPSHOT"? (com.stackoverflow:Q12840869) 1.1-SNAPSHOT: : [INFO] Transforming 'Q12840869-1.0-SNAPSHOT'... [INFO] Not generating release POMs [INFO] Executing preparation goals - since this is simulation mode it is running against the original project, not the rewritten ones [INFO] Executing goals 'clean verify'... [WARNING] Maven will be executed in interactive mode, but no input stream has been configured for this MavenInvoker instance. [INFO] [INFO] Scanning for projects... [INFO] [INFO] [INFO] [INFO] ------------------------------------------------------------------------ [INFO] [INFO] Building Q12840869-1.0-SNAPSHOT 1.0-SNAPSHOT [INFO] [INFO] ------------------------------------------------------------------------ [INFO] [INFO] [INFO] [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ Q12840869 --- [INFO] [INFO] Deleting C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target [INFO] [INFO] [INFO] [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ Q12840869 --- [INFO] [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] [INFO] Copying 0 resource [INFO] [INFO] [INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ Q12840869 --- [INFO] [INFO] Compiling 1 source file to C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target\classes [INFO] [INFO] [INFO] [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ Q12840869 --- [INFO] [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] [INFO] skip non existing resourceDirectory C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\src\test\resources [INFO] [INFO] [INFO] [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ Q12840869 --- [INFO] [INFO] Compiling 1 source file to C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target\test-classes [INFO] [INFO] [INFO] [INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ Q12840869 --- [INFO] [INFO] Building jar: C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target\Q12840869-1.0-SNAPSHOT.jar [INFO] [INFO] [INFO] [INFO] --- maven-surefire-plugin:2.7.2:test (surefire-it) @ Q12840869 --- [INFO] [INFO] Surefire report directory: C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target\surefire -reports [INFO] [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running com.stackoverflow.MainTest [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.041 sec [INFO] [INFO] Results : [INFO] [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] [INFO] ------------------------------------------------------------------------ [INFO] [INFO] BUILD SUCCESS [INFO] [INFO] ------------------------------------------------------------------------ [INFO] [INFO] Total time: 5.102s [INFO] [INFO] Finished at: Thu Oct 11 17:10:29 CEST 2012 [INFO] [INFO] Final Memory: 13M/147M [INFO] [INFO] ------------------------------------------------------------------------
答案 2 :(得分:2)
我会尝试另一种方法,并尝试配置release插件以始终使用-DskipTests
作为参数,因此您不需要每次都指定它:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin<artifactId>
<configuration>
<arguments>-DskipTests</arguments>
</configuration>
</plugin>
理论上,这应该将-DskipTests
附加到prepare
和release
目标传递给它们执行的Maven的子执行的参数上。
答案 3 :(得分:2)
使用maven-failsafe-plugin
进行集成测试,并保留maven-surefire-plugin
进行单元测试。
这将保证单元测试与集成测试完全隔离(因此可以单独关闭),并且集成测试在“integration-test
和verify
阶段运行构建生命周期“。