Http://www.cnblogs.com/holbrook/archive/2012/12/24/2830519.html
Long time no Java development, and recently completed a Java-related task, the way to re-experience maven this tool.
The use of the process found that the previous understanding of MAVEN is not deep enough to take this opportunity to re-comb the core concept of maven. I believe that understanding these core concepts, even if they are not used for a long time, will be very easy to re-use later.
In this paper, we introduce the 12 concepts of MAVEN core and the relationship between them in the way of class diagram.
Table of Contents
- 1 Maven managed Goals: Engineering (Project)
- 1.1 Engineering Dependencies
- 1.2 Engineering Aggregation Relationship
- 2 maven Core: life cycle and stages
- 3 feature implementations: Plugins and goal
- 4 Warehouse (Repository)
- 5 Summary
1 Maven managed Goals: Engineering (Project)
MAVEN is a software engineering (software Project) management tool. For Maven, the unique identity of a software engineering is determined by the developer (GROUPID), the Build (Artifactid), and the version.
Each project has a package type, which can be a jar, war, ear, or POM. The packing type determines the type of the final product of the project. wherein the POM type is used for component multi-module engineering.
There are two kinds of relationships between projects: dependency and aggregation.
1.1 Engineering Dependencies
The management of dependencies is the praised place for Maven. A project can rely on several other projects, and the unique identification (groupid+artifactid+version) of the project can clearly indicate the dependent libraries and versions, and can handle the delivery of dependencies. Maven can specify the scope of dependencies (scope), including the following:
colgroup>
scope |
compilation period |
test period |
run-time |
description |
*compile |
V |
v |
V |
default scope |
test |
|
V |
|
only depends on the test period, such as the JUnit package |
provided |
V |
V |
|
run time is provided by the container, such as Servlet-api package |
Runtime |
|
v |
v |
no direct reference required during compilation |
system |
V |
v |
&nbs P; |
provided by the native environment when compiling and testing |
Because the transitive nature of dependencies can lead to conflicting versions, scopes, and so on, MAVEN provides the quorum mechanism and allows itself to be managed by configuration.
1.2 Engineering Aggregation Relationship
The aforementioned POM types are used for component multi-module engineering, which represents an aggregation relationship between project: aggregating a series of small modules into the entire product.
By aggregating the project, you can manage the construction, cleanup, and documentation of each related module at the same time. The aggregation relationship is defined by project as the parent project that specifies a pom type in the child project.
2 maven Core: Life cycle and Stages
Maven understands the construction process of Engineering (project) as a different life cycle (LifeCycle) and phase (Phase). In the construction of the project, there are different life cycles, these life cycles are independent, there is no certain sequence relationship. Each life cycle is divided into different phases (Phase). There is a clear sequential relationship between phases, and the phases within the same life cycle must be executed sequentially.
MAVEN has built-in three lifecycles and built-in stages for each life cycle. The following is a list of Maven's built-in lifecycles and major phases:
- Default: Built (build)
- Validate: Verify that the project is correct and that all required information is available.
- Compile: Compiles the code in the project.
- Test: The compiled code is tested with the relevant unit test framework, and these run tests are not packaged and shipped with the project.
- Package: Packages the compiled code into a corresponding format file, such as a jar package.
- Integration-test: If you need to run our tests in a comprehensive environment, this phase will run and project the program into that environment.
- Verify: Check that the project's package is correct and meets the requirements.
- Install: Installs the package to the local MAVEN repository, allowing other projects to use the package as a dependency.
- Deploy: Publish the package to a remote MAVEN repository and make it available to other developers.
- Clean: Cleanup
- Pre-clean ready to clean up
- Clean performs cleanup work
- Post-clean follow-up work after cleanup
- Site: Build project documents and sites
- Pre-site preparing to generate
- Site build project sites and documents
- Post-site follow-up work after generating a document
- Site-deploy Publish project documents
For a more detailed description of phase, refer to: http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
3 feature implementations: Plugins and goal
The engineering cycles and phases defined in MAVEN are only abstract concepts and do not involve specific functionality. The specific functionality is implemented by the plug-in (Plugin). A plug-in can implement multiple targets (Goal).
To understand the functional and engineering phases of the decoupling plug-in, and to achieve a high degree of flexibility, maven dictates that the plug-in is simply a function of achieving the goal, which is configured to determine at what stage (execution) which target operations are performed. You can even bind a goal to multiple phase for reuse.
MAVEN has some default plugins built in, and some goal are bound by default in each phase based on the different project packing types. The following table lists the goal of the default bindings for each stage of the default life cycle, where goal is tagged in the way that management uses pluginname:goalname:
Pahse |
Plugin:goal |
Process-resources |
Resources:resources |
Compile |
Compiler:compile |
Process-test-resources |
Resources:testresources |
Test-compile |
Compiler:testcompile |
Test |
Surefire:test |
Package |
Ejb:ejb/ejb3:ejb3/jar:jar/par:par/rar:rar/war:war |
Install |
Install:install |
Deploy |
Deploy:deploy |
The last thing to note is that Maven's plugin is a packaging type Maven-plugin project that can use MAVEN project dependencies, configure plugins, and so on.
4 Warehouse (Repository)
Warehouses are used primarily for the generation of other engineering-dependent projects, and can also be deployed to deploy MAVEN projects. The generated objects include a variety of packaged produce and pom files.
If necessary, a project can be deployed to multiple warehouses.
Warehouses can be divided into local and remote libraries (remotes). The local library is usually located in the native ~/.m2/repository folder, and the remote library is most common with the Maven Central Library (), and some of the VMS are used within the enterprise.
http://repository.jboss.com/maven2/
5 Summary
This article combs the core concepts of MAVEN, the entire MAVEN core concept is as follows:
Concept |
Description |
LifeCycle |
Life cycle, Maven built-in Default,sie,clean three lifecycles |
Phase |
Stages, each life cycle has different stages |
Plugin |
Plug-ins for real-world build capabilities |
Goal |
A plug-in can implement multiple goal,goal with specific functions |
Execution |
By configuration, decide which goal to perform in a phase |
Project |
MAVEN Management goals: Software engineering, small projects can be aggregated into large projects |
PackageType |
In order to facilitate the management of the project, according to the construction target area into different project types, such as Jar,war,ear |
Dependency |
dependencies, there is a dependency between project |
Dependencyscope |
MAVEN defines different scopes for dependencies |
Management |
You can configure how a project manages dependencies |
Repository |
Warehouse, storage package, divided into local library and remote library |
Build |
The action of the build. Using MAVEN to manage your project, it is primarily to specify that project be built into a phase |
Understand the core concepts of MAVEN