47

I'm running mvn release:prepare -Darguments="-Dmaven.test.skip=true -DskipTests" on the master checkout of Spotify's docker-client. But I can't get maven's release plugin to skip the tests. Why doesn't maven in this case respect the CLI flags?

I'm also curious what causes the release plugin to execute the surefire-plugin. There's no surefire-plugin specified in pom.xml.

mvn --version

Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T12:29:23-05:00)
Maven home: /usr/local/Cellar/maven/3.2.5/libexec
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.2", arch: "x86_64", family: "mac"
David Xia
  • 5,075
  • 7
  • 35
  • 52

5 Answers5

138

This worked for me. I wanted to both prepare and perform the release.

mvn clean -DskipTests -Darguments=-DskipTests release:prepare release:perform
David Xia
  • 5,075
  • 7
  • 35
  • 52
  • Works like a charm! – Vlad Mihalcea Mar 06 '19 at 17:31
  • 16
    `-Darguments=-DskipTests` is enough. No need for the first `-DskipTests`. – Younes Nov 13 '19 at 10:54
  • 3
    OP's command already has `-DskipTests` under `-Darguments` so why didn't it work for him? In fact, I am noticing the same thing with a project. – haridsv May 06 '20 at 16:21
  • 2
    This doesn't answer the original question at all, I am really surprised that it still got so many up votes. For a possible root cause, see my answer: https://stackoverflow.com/a/61640653/95750 – haridsv May 06 '20 at 16:50
  • Probably all the upvoters are people like me who simply were looking for the syntax to do this. It worked for me too (specifically Youne's comment - we only need it in the Darguments param (can add double quotes to pass more than one maven param)). I don't have the same issue the OP had, I just needed to know how to skip tests. – Skystrider Feb 23 '23 at 21:30
5

I have used the following in my pom.xml

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.3</version>
            <configuration>
                <tagNameFormat>v@{project.version}</tagNameFormat>
                <arguments>-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true</arguments>
            </configuration>
        </plugin>
nrkkalyan
  • 179
  • 2
  • 5
  • 1
    There is no such setting as -Dmaven.test.skipTests. It's called -DskipTests, which just skips running the tests. In this case you've also passed maven.test.skip, which skips the compile step of tests sources alltogether so there are no tests to run anyway. TL;DR: `-Dmaven.test.skipTests=true -Dmaven.test.skip=true` can be replaced with: `-Dmaven.test.skip` – BitfulByte Oct 18 '21 at 15:24
  • 2
    Not really, skipTests compiles the tests but not runs them, while the maven.test.skip=true skips even compiling. – Olgun Kaya Nov 05 '21 at 12:55
3

This is one of the first hits in google for this problem and yet doesn't have the most likely explanation and solution, so here is my attempt.

I faced the same issue as the OP in running release:prepare with -DskipTests passed in via -Darguments not getting recognized. After digging in, I noticed that a grandparent POM (parent of the parent) has the following config:

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.5.2</version>
          <configuration>
            <arguments>-B</arguments>
          </configuration>
        </plugin>

It actually has more config, but I only show what is most relevant for this problem, which is the <arguments>-B</arguments>. This is hardcoding the arguments configuration parameter to -B instead of letting it read the arguments property. To get around, I added the below in the project pom and it started working:

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-release-plugin</artifactId>
          <configuration>
            <arguments>$(arguments)</arguments>
          </configuration>
        </plugin>
haridsv
  • 9,065
  • 4
  • 62
  • 65
  • Thanks for sharing. I've had the same problem, with an hardcoded argument in the POM overriding the CLI arguments – Ilario Dec 13 '21 at 15:56
2

This works with Maven 3.6 (and probably some earlier versions).

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.5.3</version>
    <configuration>
        <arguments>-DskipTests</arguments>
    </configuration>
</plugin>
OrangeDog
  • 36,653
  • 12
  • 122
  • 207
-10

There are two things. First if you like to run a release you need to run mvn release:perform which really runs the step for the final release and not the mvn release:prepare. If you like to skip the tests in mvn release:prepare you should use mvn -Dmaven.test.skip=true plus the given arguments you have defined.

Apart from that maven-surefire-plugin is defined in the default life cylce

Ralph
  • 118,862
  • 56
  • 287
  • 383
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • 2
    I ran `mvn release:prepare -Dmaven.test.skip=true -Darguments="-Dmaven.test.skip=true -DskipTests"` and it still ran the tests. – David Xia Mar 09 '15 at 19:38
  • 4
    @khmarbaise: according to https://jira.codehaus.org/browse/MRELEASE-700, it is `mvn release:prepare arguments='-Dmaven.test.skip=true'` – Ralph Mar 11 '15 at 18:51
  • It does not skip the tests for me either – Simon Jenkins Oct 19 '17 at 12:21
  • 1
    One of the things `release:prepare` does is update the POM version information (and commit that version). As such I would not recommend skipping the `release:prepare` step. – PatS Apr 04 '19 at 15:48