How can I get maven-release-plugin to skip my test

2019-01-12 15:01发布

How can I get the maven-release-plugin to run without triggering the tests?

I have tried

-Dmaven.test.skip=true 

and

-DskipTests 

and

-DpreparationGoals=clean

...yet none work.

Yes, I know I shouldn't release if the tests don't pass, but I don't have control over making my coworkers write reliable tests.

6条回答
Animai°情兽
2楼-- · 2019-01-12 15:36

you have too differents choices to avoid and skip tests with the release plugin

  • The first is to pass as argument on cli to the relase goal or phases by providings a -Darguments:

exemple: mvn -X -Darguments="-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true" -P release-mode release:prepare

-The second is to perform thoses arguments on your pom.xml in the build like this:

<plugin>    
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.scm</groupId>
                        <artifactId>maven-scm-provider-gitexe</artifactId>
                        <version>1.9.4</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <skip>true</skip>
                    <skipTests>true</skipTests>
                    <preparationGoals>clean validate</preparationGoals>
                    <arguments>-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true</arguments>
                    <useReleaseProfile>false</useReleaseProfile>
                    <releaseProfiles>release-mode</releaseProfiles>
                    <tagNameFormat>TEST-@{project.version}</tagNameFormat>
                </configuration>
            </plugin>

Note that the second method override the first.

I recommanded you to prepare release first on a single action and then your can edit the release.properties file on the working directorie and look the exec.additionalArguments propertie if you arguments are there. It will look like: exec.additionalArguments=-Dmaven.javadoc.skip\=true -Dmaven.test.skipTests\=true -Dmaven.test.skip\=true -P release-mode.

After you can perform the release.

查看更多
Root(大扎)
3楼-- · 2019-01-12 15:46

-Darguments="-DskipTests" is what you want, or explicitly configuring the forked executions in the pom.

查看更多
一纸荒年 Trace。
4楼-- · 2019-01-12 15:48

To skip the entire unit test, it uses argument

-Dmaven.test.skip=true

so if you want to skip the Unit test this will solve

mvn install -Dmaven.test.skip=true
mvn package -Dmaven.test.skip=true

or alternatively you can define skipTests in maven-surefire-plugin in

pom.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.12.4</version>
      <configuration>
         <skipTests>true</skipTests>
      </configuration>
</plugin>
查看更多
劳资没心,怎么记你
5楼-- · 2019-01-12 15:53

If you just want to skip integration tests, this will do it:

-Darguments="-DskipITs"
查看更多
太酷不给撩
6楼-- · 2019-01-12 15:54

-Darguments="..." passes arguments to the forked maven process, but it is important to realise that there are two different switches being used here. The -DskipTests forces maven to not run any tests, but the tests are still compiled (this is important if you have any dependencies on a test-jar type). The -Dmaven.test.skip=true forces maven to not even compile the tests, which means that any test-jars will not be generated.

So, you must use -Darguments, but to skip tests running use only skipTests, to stop them compiling use maven.test.skip.

查看更多
We Are One
7楼-- · 2019-01-12 15:57

No maven plug-in literally triggers test compilation or execution. It is the maven lifecycle phases that trigger execution(s) of one or more plug-ins, when these have bounded goals to specific phase.

So, just executing a single plug-in goal would suffice without executing tests:

mvn release:perform

or combine with project build and packaging:

mvn clean package release:perform
查看更多
登录 后发表回答