Top 10 Maven Plugins +
Whenever you start to build your project with Maven you are using plugins. There are different kinds of plugins: core plugins, packaging types or tool, reporting plugins, tools and plugins to generate IDE configurations.
Some of this plugins like clean, compile, install and others you are using everday. Maybe without to know that these are plugins.
Most of the plugins are highly configurable which helps you in the most situations. Most of the plugins are well documented on their own websites.
In this post I will present our 10 most valuable Maven plugins.
1. Maven AntRun Plugin
The Maven AntRun Plugin is the plugin we use whenever we want to do little tasks. Maven is great in solving dependencies, but Ant is very helpful in a lot of situations. Maybe you want to copy files or integrate existing Ant tasks. Yes, you can sit down and write your own Maven plugin in this situations, but then you have to deploy the plugin to all team members and have a lot of overhead in implementing your own plugin. In most situations it is easier to write a few lines of ant configuration in your pom.xml
2. Maven Surefire Plugin
The Maven Surefire Plugin is normally used, when you start the command mvn test or when you are executing a goal which includes the test goal (read more about this in Maven2 Build Lifecycle). If you are using the standard directory layout of Maven your tests can be found at src/test/java. If there are tests in this directory the Maven Surefire Plugin will automatically run these tests and generate reports including the results in the directory target/surefire-reports. Opposite to the documentation on the plugin page, the Maven Surefire Plugin will run JUnit 3/4 tests as well as TestNG tests.
3. Maven Site Plugin
The Maven Site Plugin is used more frequently but maybe not known to everybody. With the Maven Site Plugin you can generate a complete website for your project. All you need to do is to call mvn site and wait for the site to appear in the target directory. If you are developing a public available project, it is maybe all you need to generate your own website. A lot of information is taken from your configuration but you can easily include your own pages and content. We use it to include reports about our code: test results, test coverage, resolved dependencies and many more. For more information about the available reports have a look at the report plugin section on this page.
4. Maven Archetype Plugin
With the Maven Archetype Plugin you can easily generate a scaffolding of a project. You need a Struts2 application? Try out the following code:
mvn archetype:create -DgroupId=tutorial \
-DartifactId=tutorial \
-DarchetypeGroupId=org.apache.struts \
-DarchetypeArtifactId=struts2-archetype-starter \
-DarchetypeVersion=2.0.5-SNAPSHOT \
-DremoteRepositories=http://people.apache.org/repo/m2-snapshot-repository
There are archetypes for a lot of project types and you can also build your own project template. We use it to generate a stub for a portlet module with our full technology stack.
5. Maven IDEA Plugin
It can be a pain to configure the IDE with all the required libraries and settings for a project. With the Maven IDEA Plugin or the Maven Eclipse Plugin you can generate ready to start project settings files. It was important until Jetbrains had improved the Maven Support in version 7 of IntelliJ. Maybe it is still helpful for you.
6. Maven Jetty Plugin
When developing Java web applications you often find yourself configuring Tomcat, deploying WAR-files and restarting your Tomcat. With the Maven Jetty Plugin all you need to do is to call mvn jetty:run. It was never so easy to start and develop your Java web projects, because this server is running on the actual files. No copying, no deploying while your are developing. I really like it, because this one is speeding up your daily work.
7. Maven Cargo Plugin
The Maven Cargo Plugin is great for getting a container with your artifacts running. You need a JBoss? This plugin can download and start a JBoss. You need to deploy your artifacts and check until the server is started, you can use this plugin. The configuration can be a little tricky and especially when you are using features like container managed security.
8. Maven Dependency Plugin
Most problems with Maven occur in resolving the right dependencies. Often you don’t know, where the version of a library comes from or why the library is included in your artifact. With the Maven Dependency Plugin you can get all the infos you need:
- mvn dependency:tree will give you a tree view of the resolved dependencies
- mvn dependency:analyze-dep-mgt will find mismatches in your dependencyManagement section
9. Maven Javadoc Plugin
The Maven javadoc Plugin is a reporting plugin and will generate the Javadoc of your project and will include it into the site. Your Maven site can be a central point for your team members to get information about your project. The Javadoc could be one part and it is often very helpful to deploy the Maven site on a central server with your CI builds. If you are developing parts in Javascript there is also a JsDoc plugin available.
10. Maven WAR Plugin
The Maven WAR Plugin is a of the type packaging and will generate a ready to run WAR file. If you are using the standard directory layout all you need to do is to declare the type of your project as WAR and call mvn install. You can copy this WAR file into your Java web container (eventually with the Maven AntRun Plugin) and get your application running. Very helpful is the filtering feature of Maven which also works with the WAR plugin. It is very important in this case, because you can’t change or patch anything, after the WAR file is packaged.
Our plugins
Because we are facing situations where no plugin for a problem is available, we have written some plugin and released it as open source.
Maven Sizewatch Plugin: Include the plugin in the maven “verify” or “install” phase to check, that an artifact does not exceed a predefined size. This plugin can be useful to check the size of .war archives, that might contain more libs than expected when some transient dependencies have changed.
Maven Wait Plugin: We’re doing automated integration tests via Xen containers, so we didn’t need a full blown cargo installation – instead we’ve a full blown JBoss installation with database fresh and ready for tests. The wait plugin just makes sure that tests are started as soon as the server is up and running.
[...] agimatec » Blog Archive » Top 10 Maven Plugins [...]
[...] If you want the know about the best Maven plugins, check out the Top 10 Maven plugins on our blog. [...]
This cannot be complete without the supercool “Release”-Plugin :)
[...] How to say thank you to those sites and people that matter. Saved by valten on Sat 07-3-2009 Top 10 Maven Plugins Saved by jorgejiro on Mon 02-3-2009 story of your life? Saved by finleyt on Sat 28-2-2009 Book [...]