Improve the performance of your Maven builds with maven-cli-plugin

When you makes a lot of build using Maven, this is quickly a pain to wait for the end of the build. So this is always good to have solutions to improve the performances of the builds.

The better improvement i found until now is the maven-cli-plugin. This plugin provides an interactive command line interface to launch builds. The improvement is that the first phases of the build are made only once. So multiple builds are really faster. We loose a little time at the first build to make some caching improvements.

With these features, I save a lot of time when I made a lot of builds. For example a simple clean takes sometimes 20 seconds on a big multimodule project. When using the cli, it takes 20 seconds including the time to load the shell for the first time and then it takes only 1 second the make the following cleans. The effect is the same on other phases like install, package, compile, ...

The installation is quite simple. First you must add a plugin group to the settings.xml file :

<settings>
  <pluginGroups>
    <pluginGroup>org.twdata.maven</pluginGroup>
    ...
  </pluginGroups>
  ...
</settings>

And then add a new repository for the manve-cli-plugin :

<pluginRepositories>
     <pluginRepository>
          <id>twdata-m2-repository</id>
          <name>twdata.org Maven 2 Repository</name>
          <url>http://twdata-m2-repository.googlecode.com/svn/</url>
     </pluginRepository>
</pluginRepositories>

And you just have to use the following command on a Maven project :

mvn cli:execute-phase

With that the plugin will be downloaded automatically and the next commands will be executed directly.

The usage is very easy. This plugin has 2 useful goals :

  • execute : Open a shell and allows you to execute goals of plugins.
  • execute-phase : Open a shell and allows you to execute phases of the maven build.

The main difference is that if you launch install from the execute-phase, all the preceding phases will be executed, but that's not the case with execute, only install will be executed.

Personally, I only execute phases, so I always use the execute-phase of the cli plugin.

When you're in the shell, you can launch several phases or goals :

maven> clean install

And you can directly add arguments in the command :

maven> clean install -Dmaven.test.skip=true

And when you are building a multimodule projects, you can also execute phases only on several modules :

maven> module1 module2 module3 clean install

You can use the ls command in a multi module project to list all the modules of the project. You can use the "Tab" key to auto complete the goals, phases and modules name.

When you've finished your builds, you can simply use the "exit" command to exit from the command line.

I think it's really a great essential plugin for each person who make Maven builds.

More information on the official site.

Related articles

  • Maven 3.0 Beta 1 is here !
  • New design for JTheque Web site
  • Review of Jetbrains Intellij Idea 9 Ultimate Edition
  • Sonar C++ Community Plugin Review
  • 4 reasons i'm not using Osmorc anymore
  • Aggregator Plugin : Display global metrics in Sonarqube
  • Comments

    Comments powered by Disqus