Plugin in maven is the one of the vital feature that is basically used to reuse the common build logic across different projects. Plugins are the ones through which all the tasks like compiling code, testing them with the junits, creating jar/war/ear files and documentation of the projects are carried out. Most of the work in maven is done using plugins, since the dependencies (jar files) are added only to the classpath while executing tasks.
So, maven is nothing but a plugin execution framework in which every tasks are accomplished by the usage of plugins.
Below are the basic list of tasks that are handled by plugins in maven :
Behavior of any plugin can be changed using a set of parameters exposed by each plugin goal (also known as Mojo). A Mojo in maven is just a goal, basically specifies the metadata of a goal - goal name, which phase it fits into and parameters expected by the goal.
Basically 2 important types of plugins exist in maven as listed below :
<build>element in pom.xml
<reporting>element in pom.xml
Below are list of commonly used plugins in any java projects built using maven :
|clean||Used to delete the target directory in order to clean up the earlier build artifacts|
|compiler||To compile java source files|
|surefile||Executes the Junit tests and generate the reports.|
|jar||Build the jar file of the project|
|war||Build the war file of the project|
|javadoc||Generates the javadocs of the project|
|antrun||Runs a set of ant tasks specified in any stage/phase of the build|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.orgname.orggroup</groupId> <artifactId>project</artifactId> <version>1.0</version> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>id.clean</id> <phase>clean</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>Clean Phase</echo> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>