前言
在每一个pom文件的开头都会有这样几行代码
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
这里面有几个http的连接,我们依次点开看看。
http://maven.apache.org/POM/4.0.0
http://www.w3.org/2001/XMLSchema-instance
https://maven.apache.org/POM/4.0.0%20https://maven.apache.org/xsd/maven-4.0.0.xsd
https://maven.apache.org/xsd/maven-4.0.0.xsd
最后这篇里面的内容和我们代码中点进去的内容一致。
下面我们来分析一下其中的标签。
xs:element
project
<xs:element name="project" type="Model">
<xs:annotation>
<xs:documentation source="version">3.0.0+</xs:documentation>
<xs:documentation source="description">
The <code>&lt;project&gt;</code> element is the root of the descriptor.
The following table lists all of the possible child elements.
</xs:documentation>
</xs:annotation>
</xs:element>
相当于1级标签,xs:complexType是element的二级标签,所有的complexType需要在element下。
一个xml文件只能有一个root标签。例如我们尝试在xml中添加一个project标签。
xs:complexType
http://www.w3.org/TR/xmlschema-1/#element-complexType
复杂类型标签。xs:all中定义了可以使用的子标签。
Model
Contributor
Profile
Activation
ActivationFile
ActivationProperty
ActivationOS
DependencyManagement *
<xs:complexType name="DependencyManagement">
<xs:annotation>
<xs:documentation source="version">4.0.0</xs:documentation>
<xs:documentation source="description">
Section for management of default dependency information for use in a group of POMs.
</xs:documentation>
</xs:annotation>
<xs:all>
<xs:element name="dependencies" minOccurs="0">
<xs:annotation>
<xs:documentation source="version">4.0.0</xs:documentation>
<xs:documentation source="description">
The dependencies specified here are not used until they
are referenced in a POM within the group. This allows the
specification of a "standard" version for a particular
dependency.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="dependency" minOccurs="0" maxOccurs="unbounded" type="Dependency"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
这里是常见的三级结构,常见的用法如下
<dependencyManagement>
<dependencies>
<!-- spring cloud 依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- spring cloud alibaba 依赖 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Import dependency management from Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Dependency **
project 中的dependencies标签,可以在
<xs:element name="dependencies" minOccurs="0">
<xs:annotation>
<xs:documentation source="version">3.0.0+</xs:documentation>
<xs:documentation source="description">
This element describes all of the dependencies associated with a
project.
These dependencies are used to construct a classpath for your
project during the build process. They are automatically downloaded from the
repositories defined in this project.
See <a href="http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html">the
dependency mechanism</a> for more information.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="dependency" minOccurs="0" maxOccurs="unbounded" type="Dependency"/>
</xs:sequence>
</xs:complexType>
</xs:element>
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
常见的子标签看我框起来的内容。 最常见的用法
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
子标签 scope,可以指定生命周期,具体官方文档参考下面的连接
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
Exclusion
Reporting
ReportPlugin
ReportSet
BuildBase
Plugin
PluginExecution
PluginManagement
Resource
DistributionManagement
Site
Relocation
DeploymentRepository
Repository
RepositoryPolicy
MailingList
Build *
project 标签可以使用 build 标签指定(构建项目所需的信息)。
<xs:element name="build" minOccurs="0" type="Build">
<xs:annotation>
<xs:documentation source="version">3.0.0+</xs:documentation>
<xs:documentation source="description">Information required to build the project.</xs:documentation>
</xs:annotation>
</xs:element>
Build 标签可以包含的子标签。
常见用法
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
</plugin>
</plugins>
</build>
Extension
IssueManagement
Parent
Prerequisites
CiManagement
Notifier
License
Developer
Scm
Organization
|