繁体   English   中英

Maven发布:准备目标

[英]Maven release:prepare goal

我们的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在测试阶段执行测试。 这导致我们的构建失败,因为我们的测试只能在集成测试阶段运行(我们使用tomcat-maven插件在执行测试之前部署打包的war)。

我知道我们可以通过传递参数(-DskipTests等)来跳过测试。 我们不想跳过任何测试,我们只想要发布:准备执行就像任何其他maven目标一样。

任何建议/帮助都非常感谢。

将集成测试添加到默认情况下未激活的单独配置文件中。 添加触发规则或其他内容。 然后根据需要使用集成测试调用构建。 例如,在您的CI(Jenkins / Hudson,TeamCity,Bamboo等)上触发了配置文件。

您目前面临的问题是您没有在两种类型的测试之间进行分离以及它们何时应该运行。 您只需定义了您希望它们执行的阶段。这不足以让Maven的执行上下文知道您想要做什么,并且它也会在发布期间调用它们。

尝试使用更通用的方法在test阶段完全禁用maven-surefire-plugin

<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>

编辑

这是我的mvn release:prepare干运行输出mvn release:prepare使用上面配置的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] ------------------------------------------------------------------------

我会尝试另一种方法,并尝试配置release插件以始终使用-DskipTests作为参数,因此您不需要每次都指定它:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin<artifactId>
    <configuration>
        <arguments>-DskipTests</arguments>
    </configuration>
</plugin>

理论上,这应该将-DskipTests附加到preparerelease目标传递给它们执行的Maven的子执行的参数。

使用maven-failsafe-plugin进行集成测试,并为单元测试保留maven-surefire-plugin

这将保证单元测试与集成测试完全隔离(因此可以单独关闭),并且集成测试在“构建生命周期的integration-testverify阶段”期间运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM