Maven Commands

Task Link Comments
Skip Maven Plugin Link Skip Maven plugin such as spotless, findbugs and spotbugs from execution
Skip Unit Test
//Skip Unit test
mvn clean install -DskipTests

//Skip Unit Test for class
mvn test -Dtest=TestClassName
mvn test -Dtest=TestClassName1, TestClassName2 


//Skip Unit Test by Method Name Pattern
mvn test -Dtest=Test1#testFoo* 

//Run all Test except few
mvn test -Dtest=!TestClassName1
Skip unit test in specific Packages Link
Run Unit test in Parallel
mvn clean install -T 4
Display Maven Dependencies
mvn dependency:tree
Display Effective POM
mvn help:effective-pom

Command displays plugins imported by default from parent pom.xml

execute life cycle task using specific plugin
mvn groupID:artifactID:version:goal
mvn org.apache.maven.plugins:maven-checkstyle-plugin:2.5:checkstyle

Windows Commands

How to Skip Maven Plugin

  1. Create a Profile
  2. Override the plugin in child pom.xml
  3. while running mvn in command prompt pass the profile as parameter
    >>mvn clean install -Pprofile_name
    

If the plugin supports skip tag

<profiles>
    <profile>
        <id>skipTestAndDb</id>
        <properties>
            <skipTests>true</skipTests>
            <liquibase.should.run>false</liquibase.should.run>
        </properties>
        <plugin>
          <groupId>group</groupId>
          <artifactId>artifact</artifactId>
          <configuration>
           <skip>true</skip>
          </configuration>
       </plugin>
    </profile>
</profiles>

Sometimes the plugin doesn’t support skip tag, in such case define use executions tag. If there is ID in parent pom.xml then same ID should be used in child pom.xml as well. If no ID is given setting phase to none alone would work. To get the plugin details for id run mvn help:effective-pom or Intellij->Right click on project -> Maven -> Show Effective POM

<plugin>    
    <groupId>group</groupId>   
    <artifactId>artifact</artifactId>    
    <executions>
         <execution>
           <id>TheNameOfTheRelevantExecution</id>
           <phase>none</phase>
         </execution>    
    </executions>  
</plugin>