Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I skip a Maven plugin execution if "-DskipTests" or "-Dmaven.test.skip=true" is specified?

I'm using Maven 3.0.3. I have this plugin, which normally I want to run before my JUnit tests are executed:

    <profile>         <id>dev</id>         <activation>             <activeByDefault>true</activeByDefault>         </activation>         <properties>             <test.mysql.db.user>sbjunituser</test.mysql.db.user>             <test.mysql.db.password></test.mysql.db.password>             <test.mysql.db.prefix>sbjunit</test.mysql.db.prefix>             <test.mysql.db.sid>${test.mysql.db.prefix}_${project.artifactId}</test.mysql.db.sid>             <test.mysql.db.host>localhost</test.mysql.db.host>             <test.mysql.db.port>3306</test.mysql.db.port>             <test.mysql.dataSource.url>jdbc:mysql://${test.mysql.db.host}:${test.mysql.db.port}/${test.mysql.db.sid}</test.mysql.dataSource.url>             <test.mysql.dataSource.driverClassName>com.mysql.jdbc.Driver</test.mysql.dataSource.driverClassName>         </properties>         <build>             <plugins>         <!--  Run the liquibase scripts -->         <plugin>             <groupId>org.liquibase</groupId>             <artifactId>liquibase-maven-plugin</artifactId>             <version>2.0.1</version>             <dependencies>                 <dependency>                     <groupId>mysql</groupId>                     <artifactId>mysql-connector-java</artifactId>                     <version>5.1.18</version>                 </dependency>             </dependencies>             <executions>                 <execution>                     <id>build-database</id>                     <phase>process-test-classes</phase>                     <configuration>                         <driver>com.mysql.jdbc.Driver</driver>                         <url>jdbc:mysql://${test.mysql.db.host}:${test.mysql.db.port}/${test.mysql.db.sid}</url>                         <username>${test.mysql.db.user}</username>                         <password>${test.mysql.db.password}</password>                         <changeLogFile>${project.build.directory}/db.changelog-master.xml</changeLogFile>                         <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>                     </configuration>                     <goals>                         <goal>update</goal>                     </goals>                 </execution>             </executions>         </plugin> 

However, if someone specifies -Dmaven.test.skip=true or -DskipTests, I would like to skip this plugin from running. How do I do that? I tried changing the execution phase to "test", but then my unit tests get run before this plugin, which is not what I want.

like image 987
Dave Avatar asked Apr 02 '13 14:04

Dave


People also ask

What is Maven test Skip?

In Maven, you can define a system property -Dmaven. test. skip=true to skip the entire unit test. By default, when building project, Maven will run the entire unit tests automatically. If any unit tests is failed, it will force Maven to abort the building process.

How do you ignore an integration-test?

The -DskipTests will skip the execution of both unit tests (surefire) and integration tests (failsafe). In order to just skip the integration tests, we can pass the -DskipITs system property. Finally, it's worth mentioning that the now-deprecated flag -Dmaven. test.

How can you override skipTests parameter in command line?

Skipping by default by initializing the skipTests element value to true in properties and then overriding it through the command line by mentioning the value of -DskipTests in the maven phase/build execution command.


1 Answers

This worked for me:

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

OR

<configuration>    <skip>${maven.test.skip}</skip> </configuration> 
like image 74
albogdano Avatar answered Sep 19 '22 11:09

albogdano