简体   繁体   中英

Cannot overwrite pom maven-surefire-plugin from command line

I have in pom the plugin maven-surefire-plugin with skipTests on true. However, sometimes I want to run the tests from the command line and I want to overwrite this plugin from command line and to

I tried

mvn install -DskipTests=false
but it still skips the tests...

Any idea how I can solve my problem...?
Thanks

Skipping by default is specifically discussed in the plugin documentation:

If you want to skip tests by default but want the ability to re-enable tests from the command line, you need to go via a properties section in the pom

In other words use a property for the default:

    <configuration>
      <skipTests>${skipTests}</skipTests>
    </configuration>

Define a property:

    <properties>
      <skipTests>true</skipTests>
    </properties>

Properties can be overridden from the command-line:

    mvn install -DskipTests=false

Note that the skipTests in the command-line above refers to the property, not to the plugin parameter with the same name.

Using profile can do the trick. It requires you change the pom file though it gives you the behaviour you want.

Set a property in project element

<properties>
  <runtests>false</runtests>
</properties>

Now create a profile

    <profile>
        <id>run-tests</id>
        <properties>
            <runtests>true</runtests>
        </properties>
    </profile>

in surefire plugin configuration

<skipTests>${runtests}</skipTests>

Now run mvn install -P run-tests This command will activate the profile, thus set the runtests property to true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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