Maven-pom.xml

Source: Internet
Author: User

POM: Poject object model, Project object models.

Project basic information:

Modelversion:

The version of the current POM model.

GroupId:

  The actual project that the current MAVEN project belongs to.

Artifactid:

  The actual project name of the current MAVEN project. The recommended way to use the project name-module name .

Version

The current version of the project.

Packaging:

How the project is packaged. The default is jar.

Classifier

Defines some of the subordinate artifacts of the build output. such as source code, Javadoc and so on. The classifier of a project cannot be defined directly, because the subordinate artifacts are not generated directly by default, but are generated by additional plug-in Help.

  artifactid-version [-classifier].packaging

Name

Declares a project name that is more user-friendly.

Property configuration:

Properties

    • Content Properties

${basedir}: Project root directory.

${version}: Project version.

    • Pom Properties

${project.artifactid}: Corresponds to the value of the <project><artifactId> element.

${project.build.sourcedirectory}: The project's main source directory, which defaults to src/main/java/.

${project.build.testsourcedirectory}: The project's Test source directory, default to src/test/java/.

${project.build.directory}: Project build output directory, default is target/.

${project.outputdirectory}: Project main code compiles output directory, default is target/classes/.

${project.testoutputdirectory}: Project test code compiles output directory, default is target/test-classes/.

${PROJECT.GROUPID}: Project's groupId.

${project.artifactid}: Project's Artifactid.

    • Custom properties

Properties

Property name:

    • Settings property

The user uses a property that begins with settings to refer to the value of the XML element in the Settings.xml file.

    • Java System Properties
    • Environment variable Properties

The user uses an Env. property that begins with the reference environment variable.

Dependency Management:

Dependencies: dependency information.

  dependency: single dependency information.

    groupId: the dependent group ID.

    Artifactid: a dependent group unique identity.

    Version : dependent versions.

    Type : the dependent types, corresponding to the packaging defined by the project coordinates.

    Scope : The scope of the dependency.

    Optional: Whether the tag dependency is optional.

    exclusions: exclusion of transitive dependencies.

      exclusion: exclusion of transitive dependencies.

        GroupId:

        Artifactid:

Range of dependencies:

  Used to control the relationship between dependencies and classpath (compile classpath, test classpath, run Classpath).

    • Compile: Compilation dependency range, default dependency. The range is compile dependent, which is valid for compiling, testing, and running three kinds of classpath.
    • Test: Tests the dependency range. The dependency of the range test is only valid for test classpath, which cannot be used when compiling the master code or running the project's use.
    • Provided: The range of dependencies has been provided. The range is provided dependent, valid for compilation and test classpath, but not valid at run time.
    • Runtime: Run-time dependent. The scope is runtime dependent, valid for test and run classpath, but not valid when compiling the master code.
    • System: The range of systems dependencies. The range of dependencies is consistent with provided. When you use system-wide dependencies, you must explicitly specify the path to the dependent file through the Systempath element. The Systempath element can reference an environment variable.
    • Import: Imports a dependency range. The dependency range does not have a real impact on three classpath. Valid only under the Dependencymanagement element.
Range of dependencies (scope) Valid for compilation Classpath Valid for Test classpath Valid for running Classpath Example
Compile Y Y Y Spring-core
Test - Y - Junit
Provided Y Y - Servlet-api
Runtime - Y Y JDBC Driver
System Y Y - Class libraries outside of the MAVEN repository

Transitive dependencies:

Account-email->spring-core->commons-logging

Maven parses each of the directly dependent POM, introducing the necessary indirect dependencies into the current project in the form of transitive dependencies.

Compile Test Provided Runtime
Compile Compile - - Runtime
Test Test - - Test
Provided Provided - Provided Provided
Runtime Runtime - - Runtime

When the scope of the second direct dependence is compile, the scope of transitive dependence is consistent with the scope of the first direct dependence; when the second direct dependence is on test, the dependency will not be passed, and when the second direct dependence is in the range of provided, Only the first direct dependency range is also provided dependency, and the scope of transitive dependency is also provided; when the second direct dependence is runtime, the scope of transitive dependency is consistent with the first direct dependency, but the compile exception, At this point, the scope of transitive dependency is run time.

Dependent mediation:

    • Path nearest is preferred.
    • First declaration is preferred.

Optional dependencies:

In a project's delivery dependency, an optional dependency does not have any impact on the project. In an ideal situation, an optional dependency should not be used.

Exclude dependencies:

Explicitly exclude transitive dependencies, and then manually specify dependencies. In Maven's parsed dependencies, it is not possible to have two dependencies of the same groupid and Artifactid but with a different version.

Collation dependency:

Use properties to define attributes, and then use ${} for reference.

Dependency Resolution Mechanism:

    1. Parse artifacts directly from the local file system when the dependencies are system-wide.
    2. After calculating the warehouse path based on the dependent coordinates, try to find the artifacts directly from the local warehouse, and if the corresponding artifacts are found, the resolution succeeds.
    3. In the case where the local repository does not have a corresponding artifact, if the dependent version is an explicit release build widget, traverse all remote repositories and discover, download and parse the usage.
    4. If the dependent version is release or latest, the metadata for all remote warehouses is read based on the update policy Groupid/artifactid/ Maven-metadata.xml, after merging it with the corresponding metadata of the local repository, calculates the actual value of release or latest, and then checks the local and remote repositories based on this real value, such as Steps 2 and 3.
    5. If the dependent version is snapshot, the metadata for all remote warehouses is read based on the update policy Groupid/artifactid/ Maven-metadata.xml, merge it with the corresponding metadata for the local warehouse, get the value of the latest snapshot version, and then check the local repository based on that value, or download from the remote repository.
    6. If the last resolved build is a timestamp-formatted snapshot, copy the file in its timestamp format to the non-timestamp format and use the non-timestamp format widget.

Release: Latest release version, excluding snapshot version.

LATEST: Latest version, including snapshot version.

Polymerization:

Combine multiple MAVEN projects or modules into one project for a unified build.

<packaging>pom</packaging>

<modules>

<module>{directory relative to the current Pom}</module>

</modules>

Inherited:

  Eliminate duplicate configurations.

<parent>

<groupId></groupId>

<artifactId></artifactId>

<version></version>

<relativepath>{Default value is: /pom.xml}</relativepath>

</parent>

Elements that can be inherited:

    • GroupId
    • Version
    • Description
    • Organization
    • Inceptionyear: The founding year of the project.
    • URL: The URL address of the project.
    • Developers: Developer information for the project.
    • Contributors: Contributor information for the project.
    • Disstibutionmanagement: The deployment configuration for the project.
    • Issuemanagement: Defect Tracking System information for the project.
    • Cimanagement: Continuous Integration System information for the project.
    • SCM: Version control system information for the project.
    • MailingLists: Message list information for the project.
    • Properties: The custom maven attribute.
    • Dependencies: The dependency configuration of the project.
    • Dependencymanagement: Dependency Management configuration of the project.
    • Repositories: The warehouse configuration for the project.
    • Build: Includes the project source directory configuration, output directory configuration, plug-in configuration, plug-in management configuration and so on.
    • Reporting: Includes the project report output directory configuration, report plug-in configuration, and so on.

Dependency Management:

Let the submodule inherit the dependency configuration of the parent module, while ensuring that the submodule relies on the flexibility of use.

Reactor:

A building structure consisting of all modules.

Properties

  PropertyName:

  project.build.sourceEncoding: Specifies the code to read the source code and the document.

  project.reporting.outputEncoding: Specifies the encoding of the HTML document that renders the site.

Remote Warehouse configuration:

Repositories:

Repository

Id:

Name

Url:

Releases:

Enabled

Updatepolicy: Configures how often updates are checked from the remote repository.

Never: Never check for updates.

Always: Check for updates every time you build.

Interval: Check for updates every x minutes.

Daily: Check for updates daily.

Checksumpolicy: Configure the policy for MAVEN to check the inspection and files.

Warn: Outputs a warning message when the build is executed.

Fail: Failed while executing the build.

Ignore: The checksum error is completely ignored.

Snapshots:

Enabled

Layout

Plugin Management:

Pluginmanagement:

Plugins

Plugin

GroupId:

Artifactid:

Executions:

Execution:

Id:

Phase

Goals:

Plugin Warehouse Configuration:

Pluginrepositories:

Pluginrepository:

Id:

Name

Url:

Layout

Snapshots:

Enabled

Releases:

Enabled

Project Build:

Build

Plugins

Plugin

GroupId:

Artifactid:

Configuration

Executions:

Execution: Perform the task.

Id:

Phase: The life cycle of the binding.

Goals: Specifies the plug-in target.

Goal

Resource filtering:

Resources

Resource

Directory

Filtering

Testresources:

Testresource:

Directory

Filtering

Profiles

Profile

Id:

Properties

Activation

Property: Automatically activates profile when a system attribute is present.

Name

OS: Operating system environment activation.

Name

Family

Arch

Version

File: The existence or not of the files is activated.

Missing

Exists

Activebydefault: Default activation.

-P: Activates a profile at the command line.

Project release:

Distributionmanagement:

Repository: Release repository.

Id:

Name

Url:

Snapshotrepository: Snapshot version warehouse.

Id:

Name

Url:

Project information:

Scm:

Connection

Developerconnection:

Url:

Cimanagement:

System

Url:

Developers:

Developer

Id:

Name

Email

TimeZone

Issuemanagement:

System

Url:

Licenses

License

Name

Url:

Snapshot version:

Maven timestamps the snapshot version when it is released. If the dependent version is a snapshot version when the project is dependent, the snapshot version is updated according to the update rule.

Snapshot versions should only be used across projects or modules within an organization. Projects should not rely on snapshot version dependencies outside of any organization.

MAVEN Conventions:

    • SOURCE Directory not src/main/java/
    • The compiled output directory is not target/classes/
    • Packaged as Jar
    • Package Output Directory not target/

Maven-pom.xml

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.