Maven default cycle and plug-in, Maven default cycle plug-in

Source: Internet
Author: User

Maven default cycle and plug-in, Maven default cycle plug-in

Run cmd

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
  
This archetype (Template) is a plug-in, and generate is the target command (goal)
The plug-in integrates several goal collections.
 
Maven standard project structure:

Src/main/java

Source code

Src/main/resources

Resource file

Src/main/filters

Resource Filtering

Src/main/config

Configuration File

Src/main/scripts

Script

Src/main/webapp

Web program source code

Src/test/java

Test source code

Src/test/resources

Testing Resources

Src/test/filters

Test resource Filtering

Src/it

Integration Testing (mainly used for plug-ins)

Src/assembly

Assembly descriptors

Src/site

Automatically Generated website

 
After the file is generated, there will be a pom. xml file in the root directory, followed by the src and target folders:
<Project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion> 4.0.0 </modelVersion> <groupId> com. mycompany. app </groupId> package name <artifactId> my-app </artifactId> project name. The jar package name <packaging> jar </packaging> is jar by default, the <version> 1.0-SNAPSHOT </version> version <name> my-app </name> is used for documentation <url> http://maven.apache.org </url> for documentation <dependencies> <dependency> An external dependency <groupId> junit </groupId> <artifactId> junit </artifactId> <version> 3.8.1 </version> <scope> test </scope> </dependency> </dependencies> </project>

 

Build:

mvn package
 
This package is a built-in command, which is a step of the default build cycle.
For example, if you run compile, it is automatically executed in the following order:
 
You can test it:
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
 
 
About the Build cycle: There are three built-in, default (default), clean (clear target folder), site (generate site Documentation)
 
Each cycle is composed of different steps, such as default:
  • Validate-Verification
  • Compile-Compile
  • Test-Unit Test
  • Package-Package it into jar or war
  • Integration-test-Integration test
  • Verify-Verification
  • Install-Deploy to the local code library for local calls of other projects
  • Deploy-Deploy to a remote code library for remote calls by others or projects

The following steps always start from the top and are executed in order.

The same command can execute multiple steps at the same time, such

Mvn clean install will first clean, then install
 
The goal of a plug-in represents a specific task,
A step actually calls the goal of a plug-in. The specific goal is related to the project.
Therefore, you can alsoDirectly execute the plug-in goalSuch:
mvn dependency:copy-dependencies
mvn archetype:generate
 
 
 
One cycle step can be associated with multiple plug-ins goal

1. Default Association: SpecifyPackaging of pom. xml,The default value is jar.

Procedure

Plug-in goal

Process-resources

Resources: resources

Compile

Compiler: compile (the plug-in can have multiple goal)

Process-test-resources

Resources: testResources

Test-compile

Compiler: testCompile (the plug-in can have multiple goal)

Test

Surefire: test

Package

Jar: jar

Install

Install: install

Deploy

Deploy: deploy

2. Manual Association: ThroughPlugins of pom. xml

The agent's goal itself has a default associated step, but goal may also be associated with multiple steps. You can specify

<Build> <plugins> <plugin> <groupId> com. mycompany. example </groupId> <artifactId> display-maven-plugin </artifactId> <version> 1.0 </version> <executions> plug-in configuration <execution> <phase> process-test- resources </phase> procedure <goals> <goal> time </goal> specific goal </goals> </execution> </executions> </plugin>
  </plugins></build>

This goal will be appended to the goal of that step for execution. You can also specify the sequence by yourself.

 

 

Three more detailed cycle steps and related goal tables:

Clean Lifecycle

Pre-clean

 

 

Clean

All constructed items are removed.

Clean: clean

Post-clean

 

 

Default Lifecycle

Validate

 

 

Initialize

Initialization, such as setting environment variables and creating folders

 

Generate-sources

 

 

Process-sources

 

 

Generate-resources

 

 

Process-resources

 

Resources: resources

Compile

Compile

Compiler: compile

Process-classes

Post-Compilation

Plugin: descriptor

Generate-test-sources

 

 

Process-test-sources

 

Resources: testResources

Generate-test-resources

 

 

Process-test-resources

 

 

Test-compile

Testing Compilation

Compiler: testCompile

Process-test-classes

 

 

Test

 

Surefire: test

Prepare-package

 

 

Package

 

Jar: jar And Plugin: addPluginArtifactMetadata

Pre-integration-test

 

 

Integration-test

 

 

Post-integration-test

 

 

Verify

 

 

Install

 

Install: install

Deploy

 

Deploy: deploy

Site Lifecycle

Pre-site

 

 

Site

Generate website documents

Site: site

Post-site

 

 

Site-deploy

 

Site: deploy

 

See the three xml in maven-core-3.2.5.jar \ META-INF \ plexus

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.