Common Maven Plugins

Lifecycle Plugins

There are a number of phases/goals for each lifecycle

Lifecycle Phase/Goals Notes
CLEAN Clean This plugin as only one goal which clean, it removes all files generated by the build process, basically it removes the /target directory
DEFAULT
compiler:compile
compiler:testCompiler
compiler:help
default language levels for both source and target are 1.6, uses the javax.tools.JavaCompiler but can be configured to use Javac
resources:resources
resources:Resources
resources:copy-resources
copy project resources to output directory, can be configured for encoding, source and target directories, has lots of options for copying files during build process
surefire:test used to execute unit tests of the project, supports JUnit 3/4/5 and TestNG, includes classes names Test*.java, *Test.java, *Tests.java and *TestCase.java
jar:jar
jar:test-jar
is used to build jars from compiled classes and project resources, you can configure custom manifests to make execute jars
deploy:deploy
deploy:deploy-file
used to deploy projects to remote Maven repositories, configuration is done in the pom.xml file
SITE
site:site generate web documentation for project
site:deploy deploy the site via Wagon
site:run run the site locally using Jetty as a web server
site:stage generate site to local staging directory
site:stage-deploy deploy site to remote staging location
site:attach-descriptor adds site.xml to files for deployment, this file is used by search engines
site:jar creates a jar file for deployment to a repository
site:effective-site generates the site.xml file

Common Plugins

This section I am going to give some tips on some of the lifecycles, phases or goals, I will add to this section when I pick additional knowledge

When hooking into plugins via the pom.xml file you add to the build -> plugins properties, you can see an example of this in the clean tips below, different plugins have options which I point you to the documentation.

The other point I wish to make is that you can run the plugins (or lifecycles) directly from the commandline or via IDE, you can see this in intellij below


You can hook into the Clean phase using the below, in the below example I hook into the Clean initialize phase and basically use the same goal but you are able to add additional options here if you wish to do so.


The version property basically controls what Java compiler version will be used


If you are using something like intellij then make sure the supported language is correct otherwise you will get not support version issues


The resources plugin copies the resouces directory into the target/classes directory (or into a JAR file, etc), a template of this is below just add your own directory and files


The JAR plugin creates a JAR file from the compiled class files however there are some options for example you create a manifest file or add entries to the manifest file.

The Site plugin creates a website for you to view the documenation for your project, you have some options for eample you can add additional languages, if you look at the screenshot on the right you can see that the website is created in the target directory, the website uses very basic HTML.

There are many other plugin and it depends on the version here is a list for version 3.6.0 plugins, but you might want to check your version especially if its a newer ersion as there might be more plugins available