简体   繁体   English

Maven发布:准备目标

[英]Maven release:prepare goal

We have the following config in our POM file: 我们的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>

This ensures that the tests are not executed during test phase. 这可确保在测试阶段不执行测试 Tests are executed only during integration-test phase. 测试仅在集成测试阶段执行。

However, when we prepare for release (release:prepare), maven executes the tests during test phase. 但是,当我们准备发布(发布:准备)时,maven在测试阶段执行测试。 This causes our build to fail because our tests can be run only during Integration test phase (we use tomcat-maven plugin to deploy the packaged war before the tests can be executed). 这导致我们的构建失败,因为我们的测试只能在集成测试阶段运行(我们使用tomcat-maven插件在执行测试之前部署打包的war)。

I know that we can skip the tests by passing the parameter (-DskipTests etc.). 我知道我们可以通过传递参数(-DskipTests等)来跳过测试。 We do not want to skip any tests, we just want release:prepare to execute just like any other maven goal. 我们不想跳过任何测试,我们只想要发布:准备执行就像任何其他maven目标一样。

Any suggestion/help is highly appreciated. 任何建议/帮助都非常感谢。

Add your integration tests in a separate profile which isn't active by default. 将集成测试添加到默认情况下未激活的单独配置文件中。 Add a triggerring rule or something. 添加触发规则或其他内容。 Then invoke the builds with the integration tests on a need by need basis. 然后根据需要使用集成测试调用构建。 For example, on your CI (Jenkins/Hudson, TeamCity, Bamboo, etc) triggered the profile. 例如,在您的CI(Jenkins / Hudson,TeamCity,Bamboo等)上触发了配置文件。

The problem you are currently facing is that you haven't made a separation between the two types of tests and when they should run. 您目前面临的问题是您没有在两种类型的测试之间进行分离以及它们何时应该运行。 You have simply defined the phases you would like them to execute in. This isn't sufficient knowledge of the execution context for Maven to figure out what you would like to do and it invokes them during the release as well. 您只需定义了您希望它们执行的阶段。这不足以让Maven的执行上下文知道您想要做什么,并且它也会在发布期间调用它们。

Try with the more general approach to disable the maven-surefire-plugin completely during test phase. 尝试使用更通用的方法在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>

Edit 编辑

This is the output from my dry run of mvn release:prepare with the above configured surefire 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] ------------------------------------------------------------------------

I would try an alternate approach, and try to configure the release plugin to always use -DskipTests as an argument so you don't need to specify it each time: 我会尝试另一种方法,并尝试配置release插件以始终使用-DskipTests作为参数,因此您不需要每次都指定它:

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

In theory this should append -DskipTests to the arguments that the prepare and release goals pass to the sub-executions of Maven that they execute. 理论上,这应该将-DskipTests附加到preparerelease目标传递给它们执行的Maven的子执行的参数。

Use the maven-failsafe-plugin for the integration tests, and keep maven-surefire-plugin for the unit tests. 使用maven-failsafe-plugin进行集成测试,并为单元测试保留maven-surefire-plugin

This will guarantee that the unit tests are completely segregated from the integration tests (and can therefore be turned off separately), and the integration tests are run during the " integration-test and verify phases of the build lifecycle". 这将保证单元测试与集成测试完全隔离(因此可以单独关闭),并且集成测试在“构建生命周期的integration-testverify阶段”期间运行。

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

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