Monday, December 8, 2014

A day with Maven

POM: Project Object Model

Maven has three life cycle:
  • Clean
  • default (build)
  • Site

Clean Life cycle has following phases:
  • Pre-Clean
  • Clean
  • Post-Clean
Build(or Default) life cycle has following phase(primarily used) sequence. (Build Life cycle has 23 phases):
  • prepare-resources
  • compile
  • package
  • Install
Site life-cycle has following phases:
  • pre-site
  • site
  • post-site
  • site-deploy

Syntax for life-cycle and phase:
mvn <life-cycle> : <phase>
ex: mvn clean:clean

Syntax for activating profile:
mvn <life-cycle>/<phase>   -P<profile>
ex: mvn clean -P phix

When a phase is called via Maven command, for example mvn compile, only phases upto and including that phase will execute.

In Maven terminology, a repository is a place i.e. directory where all the project jars, library jar, plugins or any other project specific artifacts are stored and can be used by Maven easily.

Maven repository are of three types
Maven is actually a plugin execution framework where every task is actually done by plugins.

A plugin generally provides a set of goals and which can be executed using following syntax:
mvn <plugin-name>:<goal-name>

Maven provided two types of plugin:
  • Build plugins (They execute during the build and should be configured in the <build/> element of pom.xml)
  • Reporting plugins (They execute during the site generation and they should be configured in the <reporting/> element of the pom.xml)

Dependency Management:
The dependency management section is a mechanism for centralizing dependency information. When you have a set of projects that inherits a common parent it's possible to put all information about the dependency in the common POM and have simpler references to the artifacts in the child POMs.

For parent:

For child: If below code is not copied in child then no dependency will be included in child project from parent. Need to define all required dependency in child project.

No comments:

Post a Comment