Apache Maven: Plugins explanation

In earlier articles we have seen about Maven’s different lifecycles and their various build phases. Now we will extend these articles to understand, what is the role of plugins in executions of various build phases like compile, test, install, deploy, etc

With every build phases, there is always a plugins associated with it and this is applicable for all three built-in lifecycles of Maven

It means every time when we execute any of the build phase, then actually a goal configured in the plugins gets executed at the background implicitly and this is not configured exclusively in the pom.xml

Reason: We need these build phases to get executed in the sequence as defined in the Maven’s lifecycle. So configuring each and every plugins with their goals is quite cumbersome for this default behavior [means maven provides these plugins on-the-fly with their associated goals, when we execute any of the build phase]

For instance, we will consider default lifecycle of Maven and understand what are the plugins associated with every build phase

Syntax: [plugin:name]:[goal-name]

Build Phase plugins:goal
compile compiler:compile
test surefire:test
package jar:jar (depending on the POM element <packaging>)
install install:install
deploy deploy:deploy

Note: Plugins just instructs, actually configured goals in the plugins gets executed

All we learnt so far is the default behavior, now we will move on to understand how we can manually configure <plugins> under <build> section of pom.xml

Sometime, we need extra bit of work to be done in addition to the default behavior. So to achieve this, we can manually configure <plugins> in pom.xml

For instance, we will consider jaxws plugins


Plugin –> jaxws
Goal   –> wsimport
Phase –> generate-sources

Above plugin in which configured “wsimport” goal reads the WSDL file from location specified and generates jax-ws classes at “generate-sources” build phase of the Maven’s default lifecycle

Note:  With <phase> tag, we can specify at which step of the lifecycle this needs to be executed




Read Also:


Happy Coding !!
Happy Learning !!