Updated March 20, 2023
Introduction to Maven Plugins
Maven Plugins is a project management tool. Maven is based on the Project Object Model i.e. POM. Primarily maven is used as a build automation tool for Java projects. Maven can be used with other programming languages e.g.: Ruby, scala, etc. Plugins are where the real action takes place in project execution.
Example: Compiling Code, Testing Code, and Creating JAR/WAR files, etc…
Types of Maven Plugins
It provides two types of plugins:
- Build Plugins: Build Plugins will be executed during the build process and they should be configured in the<build> <build/> tag of POM file.
- Reporting Plugins: Reporting Plugins will be executed during site generation and should be configured in <reporting><reporting/> tag of POM file.
Different Plugins Supported by Maven
Below are mentioned some of the different Plugins of Maven:
1. Core Plugins of Maven
Plugins refer to the default phases (i.e. clean, compile) may also have multiple objectives.
|Install||Install the build artifact into the local repository.|
|Clean||Clean up after a build.|
|Compiler||Compiles java program.|
|Deploy||Deploy the build artifact to the remote repository.|
|Resources||Copy the resources to the output directory for including in the JAR|
|Verifier||Useful for integration tests – verify the existence of certain conditions.|
|Surefire||Run the JUnit unit tests in an isolated classloader.|
|Failsafe||Run the JUnit integration tests in an isolated classloader.|
2. Reporting Plugins
These Plugins generate reports and execute under generation lifecycle
|Javadoc||Generates Javadoc for the project.|
|Changelog||Generate a list of recent changes from SCM (Software Configuration Management).|
|Changes||Generate a Report from an issue Tracker.|
|checkstyle||Generate a Check style report.|
|Dock||Documentation checker plugin.|
|Doap||Generate a Description of a Project file from a POM (Project Object Model).|
|Jdeps||Run JDK’s JDeps tool on the project.|
|JXR||Generate a source cross-reference.|
|PMD||Generate a PMD report.|
|Project-Info-Reports||Generates standard project reports.|
|Surefire-Report||Generate a report based on the results of unit tests.|
|Link Checks||Generate a Link check report of your project’s documentation.|
3. Packaging Tools/Types
These relate to packaging types
|EAR||Generate an EAR(Enterprise Application ARchive) from the current project|
|EJB||Build an EJB (Enterprise Java Bean) from the current project.|
|JAR||Build a JAR (Java ARchive) from the current project.|
|RAR||Build a RAR (Roshal Archive) from the current project.|
|WAR||Build a WAR (Web application ARchive) from the current project.|
|Source||Build a source-JAR from the current project.|
|Jlink||Build Java Run Time Image.|
|App-Client/acr||Build a JavaEE application client from the current project.|
4. Miscellaneous tools available through Maven by default
These are by default tools that are available through Maven
|Antrun||Run a set of ant tasks from a phase of the build.|
|Assembly||Build an assembly of sources or binaries.|
|Archetype||Generate a skeleton project structure from an archetype.|
|Dependency||Dependency manipulation and analysis.|
|Enforcer||Environmental constraint or User Custom Rule Execution.|
|GPG||Create signatures for the artifacts and POMS.|
|Help||Get information about the working environment for the project.|
|Invoker||Run a Set of Maven Projects and Verify the Output.|
|Patch||Use the gnu patch tool and apply patch files to source code.|
|Generate a PDF version of project documentation.|
|Plugin||Create a Maven plugin descriptor for any mojos found in the source tree, to include in the JAR.|
|Release||Release the current project, update the POM.|
|Remote-Resources||Copy remote resources to the output directory for inclusion in the artifact.|
|SCM||Execute SCM commands for the current project.|
|Stage||Assists with release staging and promotion.|
|Toolchains||Allows sharing configuration across plugins.|
|Scm-Publish||Publish the Maven website to an scm location.|
Configuring of Maven Plugins
The Configuration to Plug-ins are given below:
<project> <groupId>com.org.educba.Example</groupId> <artifactId>Jar_Name</artifactId> <version>1.0-SNAPSHOT</version> <packaging>Jar</packaging> <name>Jar_Name</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <build> <plugins> <plugin> <groupId>org.edu</groupId> <artifactId>edu-maven-plugin</artifactId> <version>1.2.4</version> <executions> <execution> <goals> <goal>bind</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
- In most cases, Plugins should be added within the build/plugin section.
- Adding plugins in the build/plugins section directly part of the default maven builds.
- Adding plugins in build/plugin management/plugins are not part of default maven build, it’s a management.
- Ordering of plugins sections within pom.xml is irrelevant in most of the cases.
- Plugin elements within build/plugins sections may be important.
- Maven 3.0.3 version plugin execution will be invoked in their order of declaration in pom.xml file, the order is required in this case it may affect the behavior of the build process.
Since maven is built-in plugins based architecture; it enables the users to make utilization of any application through standard inputs. Plugins are the central feature of Maven allows reuse of common build logic with multiple projects. Plugins behavior can be customized through unique plugin parameters exposed by a description of each plugin goal.
One of the most important features of maven is dependency management i.e. automatic updating and dependency closure. It also has the ability to handle multiple projects simultaneously. Dependencies and repositories are external java files required for project repositories i.e. JAR files, Maven automatically downloads the repositories from the central maven repository and puts in a local repository in case of absence.
This is a guide to Maven Plugins. Here we discuss the basic concept along with types of Plugins in Maven, Configuring Plug-ins as well as some different plugins that are supported by Maven. You can also go through our other suggested articles to learn more –