Maven lifecycle and plug-in (2)

Source: Internet
Author: User

Plug-in configuration


Definition: plug-in goals

After learning about the maven plug-in, we found that writing an independent plug-in for each function is obviously not desirable, because there are a lot of reusable code behind these tasks. Therefore, these functions are integrated into a plug-in. Every function is called a plug-in goal.

For example:

Maven-dependency-plugin has more than 10 targets, each of which corresponds to a function.

Analysis Project dependency: Dependency: Analyze

List project dependency trees: Dependency: Tree

List all resolved dependencies of a Project: Dependency: List


Global configuration of plug-ins in POM

Some parameter values will not change from Project Creation to project release, or are rarely changed. In this case, you can perform global configuration in POM. xml.

For example, configure a general Java version.

        <build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><configuration><source>1.6</source><target>1.6</target></configuration></plugin></plugins></build>

In this way, you can use this configuration no matter whether Maven-compiler-plugin: Compile is bound to the compile stage or Maven-compiler-plugin: testcompiler stage, compile Based on Java 1.6.


Configure a plug-in task in POM


Get plug-in information


Online plug-in information

Source of Maven plug-in: Basically all major Maven plug-ins come fromApache and codehaus

Because Maven itself belongs to Apache, there are manyOfficialAnd they have good stability.

In addition to Apache, Mojo projects hosted on codehaus also provide a large number of Maven plug-ins. (Note: The documents and reliability of these plug-ins are relatively poor. If there is a problem during use, you can only view the source code by yourself)


Plug-in parsing mechanism and FAQs

Like the dependency component, the plug-in component is also stored in the maven repository based on coordinates. When necessary, Maven searches for plug-ins from the local repository. If no plug-in exists, it searches for plug-ins from the remote plug-in repository. Find the plug-in and download it to the local repository.


Note: Dependent remote repository! = Plug-in remote repository, Maven treats them differently.

Required by MavenDependencyMaven does not exist in the local repositoryYesSearch in the configured Remote Repository

Required by MavenPlug-insMaven does not exist in the local repositoryNoSearch for these remote repositories.


How to configure remote repository for plug-ins

Use <pluginrepositories> and> <pluginrepository> to configure the maven plug-in remote repository.

The remote repository configuration of the plug-in built in Maven is as follows: it disables support for snapshot to prevent unstable building.

<pluginRepositories><pluginRepository><id>central</id><name>Maven Plugin Repository</name><url>http://repo1.maven.org/maven2</url><layout>default</layout><snapshots><enabled>false</enabled></snapshots><releases><updatePolicy>never</updatePolicy></releases></pluginRepository></pluginRepositories>

Simple Configuration:

1.2 omit the groupid Configuration:

Maven provides a simple configuration policy for its official plug-ins. Its official groupid is Org. apache. maven. plugins, which can be omitted during configuration. MAVEN automatically uses the default groupid when parsing the plug-in. However, this method is not recommended in general, because only one line of configuration is left, and it is easy to confuse new users.

2. Skip version Configuration:

Maven pom adopts the Inheritance Mechanism (which is detailed in Maven aggregation and inheritance). MAVEN has a super pom, and all projects inherit the configuration of this super pom, therefore, if you do not add any configuration, their version is determined when Maven uses the core plug-in.

Maven-clean-plugin

Maven-compiler-plugin

Maven-surefire-plugin

If the plug-in version is not configured during configuration, Maven traverses the local repository and all remote plug-in repositories and merges the repository metadata under this path, you can calculate the latest and release versions.

In maven2: If no version is configured, it will be parsed to the latest version by default. This version may have potential problems. For example, this version is a snapshot version.

In maven3: if the version is not configured, it will be resolved to the release version by default, which solves the stability problem, but this may also have potential problems, for example, the behavior of the new version changes with that of the old version, and the build fails.

So: when using the plug-in, the set version should be displayed.






Buddha's Filial Piety: All beings are parents, and all good filial piety is the first.

Knowing that there is no difference between the heart, the Buddha, and the sentient beings. Only by knowing that caring for others is about caring for yourself, while caring for others is about saving yourself. Being nice to others is about being nice to yourself, all beings are treated as their parents to save their lives. This is the filial piety of the Buddha.

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.