What is Maven
Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.
Below are features provided by maven:
- Build Automation Tool
- Dependency Management Tool
- Project Management Tool
- Standard approach to building software
- Command line tool
- IDE Integration
- Managed by Apache Software Foundation
Terminologies
- POM(Project Object Model)
- POM is an XML file, and this file really describes the configuration and the customization for our project. So it's going to spell out the different plugins, different dependencies and different profiles that we use to construct our project.
- Within this POM, minimal requirement is to have GAV parameters. Maven uses a coordinate system, where you specify GAV - group ID, artifact ID and version number.
- Repositories
- where all the built artifacts and dependencies stored.
- There are 2 types of repo. - local(cache) and remote.
- Local repository take precedence for dependencies to download.
- Local repo created as hidden .m2 directory in home dir. of userid
- Lifecycle and Phase
- When maven runs the build process it goes through it build lifecyle. There is clearly defined process of building and distributing the artifact.
- There are 3 build lifecycles:
default
,clean
andsite
default
- Handles project management. This is majorly used lifecycle.clean
- Handles project cleaning.site
- Create project site documentation.- Lifecycle consists of Phases. Phase is a stage in the lifecycle through which build go through.
- Phases of
default
lifecycle For the complete list of default lifecycle phases please refer this link validate
- Validates the project if contains all necessary informationcompile
- Compile the source codetest
- Test the source code using unit test cases written undersrc/test/
directorypackage
- Create package containing with all compiled code ex. jar, war which contains classes of javaverify
- Runs integration checks ex. source code is written according to predefined checkstyleinstall
- Install the package to local repository, means copy the package from target directory to~/.m2/repository/groupID/artifactID/versionNumber/
directorydeploy
- Upload the artifact to remote repository- When any phase is getting executed in lifecycle, maven execute all precedence phases.
- Ex. when we run
mvn package
maven will run all phasesvalidate, compile, test
before "package" in order - Plugins and Goals
- Individual build phase is made up of Plugin
- Plugin is a collection of goals with default goal attached to it.
- Ex. when we run
mvn package
maven default run pluginjar
which has default goaljar
- Plugin and Goal are described as
plugin:goal
ex.jar:jar
- Goal performs the actual action in build process.
- Few example of default lifecycle phase and their default plugin and goal
- How to configure Plugins and Goals
- A Plugin contains default and other goals. Ex.
compiler
plugin contains 2 goals:compile
andtestCompile
- Plugin and Goal can be configured within POM.xml and command line.
- Using POM.xml
Default Lifecycle Phase | Default Plugin:Goal |
---|---|
compile |
compiler:compile |
test |
surefire:test |
package |
jar:jar |
install |
install:install |
deploy |
deploy:deploy |
<plugin>
<groupId>com.mycompany.example</groupId>
<artifactId>display-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>process-test-resources</phase>
<goals>
<goal>time</goal>
</goals>
</execution>
</executions>
</plugin>
mvn help:effective-pom
Here help is plugin and effective-pom is goal.- This command would return super pom.xml file details.
Comments
Post a Comment