Motivation

Suppose you have a big project with tens or hundreds of Maven modules.

Some of them are that kind which only packages things, or intentionally has no tests, or no resources, etc.

 

Suppose the first case, when you just create a .jar with some resources.

During the build, this is what you would see:

 

[INFO] ------------------------------------------------------------------------
[INFO] Building JawaBot 2.0 conf/redhat-test 2.0.0.GA-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ JawaBot-config-redhat-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ JawaBot-config-redhat-test ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ JawaBot-config-redhat-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/ondra/work/TOOLS/JawaBot/configs/redhat-test/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ JawaBot-config-redhat-test ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ JawaBot-config-redhat-test ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.2:jar (default-jar) @ JawaBot-config-redhat-test ---
[INFO] Building jar: /home/ondra/work/TOOLS/JawaBot/configs/redhat-test/target/JawaBot-config-redhat-test-2.0.0.GA-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.3:install (default-install) @ JawaBot-config-redhat-test ---
[INFO] Installing /home/ondra/work/TOOLS/JawaBot/configs/redhat-test/target/JawaBot-config-redhat-test-2.0.0.GA-SNAPSHOT.jar to /home/ondra/.m2/repository/org/jboss/jawabot/configs/JawaBot-config-redhat-test/2.0.0.GA-SNAPSHOT/JawaBot-config-redhat-test-2.0.0.GA-SNAPSHOT.jar
[INFO] Installing /home/ondra/work/TOOLS/JawaBot/configs/redhat-test/pom.xml to /home/ondra/.m2/repository/org/jboss/jawabot/configs/JawaBot-config-redhat-test/2.0.0.GA-SNAPSHOT/JawaBot-config-redhat-test-2.0.0.GA-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.755s
[INFO] Finished at: Sun Jul 07 05:05:54 CEST 2013
[INFO] Final Memory: 10M/213M
[INFO] ------------------------------------------------------------------------

 

But you don't really need all those steps. These executions do nothing:

 

maven-compiler-plugin:3.1:compile (default-compile)
maven-resources-plugin:2.6:testResources (default-testResources)
maven-compiler-plugin:3.1:testCompile (default-testCompile)
maven-surefire-plugin:2.15:test (default-test)

 

It's just a second and something (on an SSD disk, though), but that's still worth saving.

Fortunatelly, there's a way to disable these executions.

Disabling unnecessary plugin executions

Notice the identifier in parentheses. That's the execution ID.

If you check so-called super-POM, it has default bindings of the plugin executions for some module type, which you then see even if your pom.xml doesn't define them.

 

If you re-define them and bind them to a non-existent phase, they won't run:

 

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <executions>  <execution> <id>default-test</id> <phase>none</phase> </execution> </executions>
</plugin>

 

The same way, you may disable all the other executions.

 

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <executions> <execution> <id>default-test</id> <phase>none</phase> </execution> </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <executions>
        <execution> <id>default-compile</id> <phase>none</phase> </execution>
        <execution> <id>default-testCompile</id> <phase>none</phase> </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <executions> <execution> <id>default-testResources</id> <phase>none</phase> </execution> </executions>
</plugin>

 

The result

[INFO] ------------------------------------------------------------------------
[INFO] Building JawaBot 2.0 conf/redhat-test 2.0.0.GA-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]  
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ JawaBot-config-redhat-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-jar-plugin:2.2:jar (default-jar) @ JawaBot-config-redhat-test ---
[INFO] Building jar: /home/ondra/work/TOOLS/JawaBot/configs/redhat-test/target/JawaBot-config-redhat-test-2.0.0.GA-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.3:install (default-install) @ JawaBot-config-redhat-test ---
[INFO] Installing /home/ondra/work/TOOLS/JawaBot/configs/redhat-test/target/JawaBot-config-redhat-test-2.0.0.GA-SNAPSHOT.jar to /home/ondra/.m2/repository/org/jboss/jawabot/configs/JawaBot-config-redhat-test/2.0.0.GA-SNAPSHOT/JawaBot-config-redhat-test-2.0.0.GA-SNAPSHOT.jar
[INFO] Installing /home/ondra/work/TOOLS/JawaBot/configs/redhat-test/pom.xml to /home/ondra/.m2/repository/org/jboss/jawabot/configs/JawaBot-config-redhat-test/2.0.0.GA-SNAPSHOT/JawaBot-config-redhat-test-2.0.0.GA-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.181s
[INFO] Finished at: Sun Jul 07 05:28:48 CEST 2013
[INFO] Final Memory: 7M/148M
[INFO] ------------------------------------------------------------------------

 

We saved around 30 % of the build time.

 

Now you probably hate me because it only speeds up modules like this :-) But still even few seconds and smaller logs is worth doing this change.

And that's not all.

Be smart, type less

Maven's plugin configuration is inherited from parent.

So if you have multiple modules, you may put these suppressing <plugin> elements to some umbrella pom and then just use that as a parent for the modules.

 

This umbrella may inherit from your project's pom - it won't affect the rest of the project.

As you may see, I don't define plugin versions in my example above; that's because I've set them in <pluginsManagement> in my project's root.

 

Deploying only the distribution .jar

The above technique can also be used to control what artifacts to deploy.

Assume you only want to deploy (upload) a distribution .jar of your application, since the modules are useless for public users.

 

In this case, you'd disable `default-deploy` (or what the name is) in the root `pom.xml`:

 

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <executions> <execution> <id>default-deploy</id> <phase>none</phase> </execution></executions>
    </plugin>

And then enable it for submodules:

 

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <executions> <execution> <id>default-deploy</id> <phase>deploy</phase> </execution></executions>
    </plugin>