Part of pom.xml
• Project dependencies
• Build profiles
• Project version
• Mailing list
GroupID Is the id of the project’s group
ArtifactID is the id of the projects
Version Is the version of the project
All pom inherits from super pom parent pom
Maven Build Lift Cycle
Phase Handles Description
prepare-resources resource copying Resource copying can be customized in this
compile compilation Source code compilation is done in this phase.
package packaging This phase creates the JAR / WAR package as
mentioned in packaging in POM.xml.
install installation This phase installs the package in local / remote
There are always pre and post phases which can used to register goals which need to be executed pre or post phase.
Maven when executed it steps through the define phase and execute the goal registered with each of the phase. Maven has following three lifecycles:
A goal represent a specific task which may be bound to zero or more build phases some goals can reside outside phases also and can be called independently of phases.
When maven executes post-clean command maven invokes the clean lifecycle consisting of the following phases.
• Pre clean
Maven clean goals deletes the build directory
Maven site plugin is generally used to create fresh documentation to create reports,deploy site etc
• Pre site
• Post site
• Site deploy
Maven build profile
A build profile is a set of values that can be used to set or override default values of Maven build using build profile we can customize the build for different environments such as QA,UAT,PRODUCTION.
Profiles are specified in pom.xml using activeProfiles/Profiles elements and are triggered in variety of ways.
Build Profile Types
- Per Project Defined in project pom file
- Per user Defined in Maven settings.xml file (%user_home%/.m2/settings.xml)
- Global Defined in Maven global settings.xml file (%M2_HOME%/conf/settings.xml
Sample command : mvn test –Ptest
A maven repository is a place i.e. directory where all the project jars,library jars,plugins other project artifacts are stored and can be used by Maven.
Maven repositories are of three types:-
Maven local repository is a folder location on your machine. Its gets created when you run any maven command for the first time.
When we run the maven it automatically downloads all the dependencies under local repository
by default it gets created under %USER_HOME% directory. To override the default location, mention another path in Maven settings.xml file available at %M2_HOME%\conf
It’s a maven community repository maintained by maven community under the url: http://repo1.maven.org/maven2/
• This repository is managed by maven community
• It is not required to be configured
• It requires internet access to be searched
Remote repository is developers own repository in case dependencies are not found under central as well as local repository it’s searched the same under remote repository.
Maven Dependency search sequence
• Searches dependencies under local repository if not found goes central repository in case not in central repository than go to remote repository if remote repository not specified throws error message
• Search dependency in central repository if not than to remote repository
• If remote repository not mentioned maven finds error