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
Plugins explanation:
- 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>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>basic</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<keep>true</keep>
<wsdlDirectory>${basedir}\src\main\resources</wsdlDirectory>
<wsdlFiles>
<wsdlFile>com\jaxws\series\top\down\approach\services\BookService.wsdl
</wsdlFile>
</wsdlFiles>
<sourceDestDir>${basedir}\generated\java\source</sourceDestDir>
<verbose>true</verbose>
<target>2.1</target>
</configuration>
</plugin>
- 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
Useful Eclipse IDE shortcuts :
- Eclipse IDE – How to show line numbers ?
- Eclipse IDE – How to GO TO any line number directly ?
- Eclipse IDE – How to remove unused imports ?
- Eclipse IDE – How to clean project ?
- Eclipse IDE – How to build Java project automatically ?
- Eclipse IDE – How to comment and un-comment line & block ?
- Eclipse IDE – How to generate constructor using fields ?
- Eclipse IDE – How to generate getters and setters ?
- Eclipse IDE – How to search files ?
- Eclipse IDE – How to locate methods in Java file ?
- Eclipse IDE – How to open editor using CTRL + E ?
- Eclipse IDE – Java compiler compliance level issue
Related Articles:
- Apache Maven – Introduction
- Apache Maven – Install on Windows 7 OS
- Apache Maven – Settings.xml explanation
- Apache Maven – Proxy setting explanation
- Apache Maven – pom.xml explanation
- Apache Maven – Plugins explanation
- Apache Maven – Changing default Maven repository location in Windows 7 OS
- Apache Maven – Local, Central and Remote Repositories
- Apache Maven – Installing custom library into local repository
- Apache Maven – Transitive dependencies explanation
- Apache Maven – Exclusion of Transitive dependencies
- Apache Maven – Dependency Scopes
- Apache Maven – Skipping unit test using surefire plugin
- Apache Maven – Exclusions and Inclusions of unit test
- Apache Maven – offline execution
- Apache Maven – Co-ordinates explained
- Eclipse + Maven – Integration
- Eclipse + Maven – How to import Maven project with pom.xml ?
- Eclipse + Maven – Setting M2_REPO classpath variable in IDE
- Eclipse + Maven – M2_REPO is Non Modifiable
- Eclipse + Maven – Creating and exploring projects using archetypes
- Eclipse + Maven – Converting Web project to Maven project
- Eclipse + Maven – mvn eclipse:eclipse command
- Eclipse + Maven – Plugin execution not covered by lifecycle configuration
References:
- http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Packaging
- http://en.wikipedia.org/wiki/Apache_Maven#Plugins
- https://www.benchresources.net/apache-maven-lifecycle-and-basic-operations
Happy Coding !!
Happy Learning !!