Maven release plugin executes tests twice

Viewed 463

When release:clean release:prepare release:perform is executed , the tests are executed twice

Once at release:prepare , stage run-preparation-goals , task clean verify

And another time on release:perform ,stage run-perform-goals , task deploy

Is there any configuration option to make tests run only on first one and not being executed on perform?

BR

Yulian Oifa

4 Answers

That's because 2 full builds are run as part of the commands you issue.

The release:prepare section performs lots of checks on the code & repository, and does a full build to ensure all tests pass.

The release:perform section tags the repo, then pulls that tag. It performs a build based on that tag and the releases that build to your artefact store of choice (Nexus/Artifactory/wherever).

These steps are designed this way to ensure you don't pollute your repo with a tag on code that doesn't build, and tests are an integral part of your build. Once maven is happy your code is good to go, it creates the tag, and pulls it so it knows for sure that the code being released is the code referenced by the tag, and nothing else. Building that tag for release requires a full build, including the tests.

You can skip the tests on one or other of the steps, or on both, but you're missing the point of tests, and of the release plugin, if you do that.

Eventually i had to change a logic.

I have executed mvn clean install release:clean release:prepare release:perform -Pmaven-release

and create a maven-release. As result the tests are executed only at install

BR

Yulian Oifa

<profile>
        <id>maven-release</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <configuration>
                        <autoVersionSubmodules>true</autoVersionSubmodules>                         
                        <arguments>-Dmaven.test.skip</arguments>                        
                    </configuration>
                </plugin>
            </plugins>
        </build>        
    </profile>

You can skip running the tests (managed by surefire plugin) with an explicitly specified parameter -DskipTests:

Something like this:

mvn release:perform -DskipTests 

For intergration tests (managed by failsafe plugin) you can use a similar flag: -DskipITs

If you don't want even compile the tests you can use -Dmaven.test.skip=true (for both unit and integration tests)

You can override the goals parameter and add -DskipTests=true.

This parameter will skip the tests only on the perform part.

Related