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