What is Maven Plugins?
In this Topic, we are going to learn about What is Maven Plugins and the different aspects of a project lifecycle like reporting, documentation, and so on could be managed by a comprehensive tool known as Apache Maven which works on a primary source of information.
The need to standardize a project in order to ensure clarity in its definition, development, and sharing of the resources led to the emergence of Maven. The advent of Apache Maven has undoubtedly simplified and made life easier for the Java Developers.
Build under the Apache license, Maven repository consists of various libraries. It also makes sure any sort of conflicts pertaining to getting the right JAR files is avoided as it has all the required dependencies such as Hibernate, spring, etc. in its repository.
In Apace Maven, the pom.xml file is the most important file where the required dependencies for a project such as Hibernate need to be mentioned. Next is the ArtifactId or the GroupId which ensures each project in the Maven is unique. The package used for the project is described by the combination of ArtifactId with the GroupId.
The build tool is the first subset in the Maven where the artifacts are deployed in the server and enable the automation and the integration of the build tools. Next is the task of managing the resources, plugins, and the dependencies in a project which is done by the Dependency Management. The scope of dependency should be known beforehand to avoid any conflict in the use of the dependency for a particular instance. The Project Management is the third subset of the Apache Maven consisting of the pom.xml file. Proper documentation of the code and information about various aspects like missing tasks, versions, etc. could be maintained in this phase. The consistency is maintained across different projects in Maven as every project maintains a standardized directory.
So far, we have learned about Maven and its functionalities in brief. Next, we would look into the plugins of Apache Maven in detail.
As seen earlier, Maven provides a standardized way to maintain each project by proving all the necessary JAR files, and dependencies in its repository and separates one project from another via a unique id.
Now, all the work in Apache Maven is done by the plugins and hence is often called a plugin execution framework. The Plugins are divided into:-
- Build Plugins – During the build, the build plugins are executed, and needs to be configured in the <build/> element present in the pom.xml file.
- Reporting Plugins – The pom.xml file has the <reporting/> element tag in which the reporting plugins needs to be configured. During the site generation stage, the reporting plugins are executed, and hence the plugins are localized, as well as internationalized.
Localization is a process of adapting to a different language during the site generation stage by translating a few downloaded property files and translating the texts in those files.
The Apache Maven plugins are up to date and are maintained in the org/apache/maven/plugins/ subfolder. The organization of the package follows a standard directory structure resembling the naming convention of the Java package.
Below are some of the core plugins in Apache Maven which are mostly used in the phases like clean, compile, etc.
- clean – Once the build is completed, these plugins cleans it up.
- compiler – The Java source file is compiled by the compiler plugin.
- deploy – The built artifact is deployed to a remote repository via the deploy plugin.
- failsafe – In an isolated classloader, the failsafe plugin is used to run the JUnit integration.
- install – The built artifact is installed into the local repository with the help of this plugin.
- resources – The inclusion of the JAR is done by copying the resources to the output directory with this plugin.
- site – The generation of the site for a project is done with the site plugin.
- verifier – To verify certain conditions, and to ensure integration tests, the verifier plugin is useful.
There are also some plugins which are involved in Packaging.
- ear – The current project generates an EAR via the ear plugin.
- ejb – The current project builds an EJB via the ejb plugin.
- jar – The current project builds a JAR via the jar plugin.
- rar – The current project builds a RAR via the rar plugin.
- war- The current project builds a WAR via the war plugin.
- shade – The current project builds an Uber-JAR via the war plugin
- jlink – The Java run-time image is built by this plugin.
- jmod – The Java JMod files are built by this plugin.
Apart from the build, and the Packaging plugins, there are also the reporting plugins.
- changelog – A project could have multiple recent changes which are generated by the changelog plugin from the SCM.
- changes – For report generation from the change document.
- doap – A project description is important to ensure clarity of the work. The doap plugin allows its generation from the pom.xml file.
- docck – To check all the documentation, the docck plugin is used.
- javadoc – The java documentation for a project is done via the Javadoc plugin.
- jxr – The cross-reference of the source is generated with the jxr plugin.
- linkcheck – The project documentation has the Linkcheck report generated with this plugin.
- pmd – The PMD report is generated by the pmd plugin.
- project-info-reports – The project reports in a standard format is generated with this.
There are several default miscellaneous tools present as well in Maven.
- ant – The project’s ant build file is generated with the Ant plugin.
- archetype – The project structure in a skeleton format generated from the archetype.
- dependency – The dependencies are manipulated and analyzed with the dependency plugin.
- patch – The patch files are applied to the source code with gnu patch tool
- release – The pom.xml file is updated, and the SCM is tagged after the project is released.
- pdf – The project’s documentation could be transformed into a pdf version with this plugin.
- scm-publish – The website built in Maven is published to an scm location with this plugin.
- stage – To ensure the staging, and promotion after a release.
This has been a guide to What is Maven Plugins. Here we discussed the Basic concepts of Maven Plugins and its functionalities. You can also go through our other suggested articles to learn more –