<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sang</groupId>
<artifactId>chapter01-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>chapter01-2</name>
<description>使用IntelliJ IDEA创建Spring Boot项目</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
不同标签含义的学习
这些标签是用于描述和管理项目依赖和构建配置的 Maven POM(Project Object Model)文件中常见的元素。下面是它们的区别:
-
<dependencies>
和<dependency>
:<dependencies>
元素是包含多个<dependency>
元素的容器。它用于列出项目所依赖的外部库、框架或模块。<dependency>
元素用于定义一个单独的依赖项,指定其坐标(groupId、artifactId 和 version),以及其他属性,例如作用域(scope)和传递性(transitivity)等。
-
<dependencyManagement>
:<dependencyManagement>
元素用于集中管理依赖项的版本信息,以确保项目中的所有模块使用相同的依赖版本。它通常位于 POM 文件的顶层,其中列出的依赖项会被子模块继承。- 在
<dependencyManagement>
中声明的依赖项不会直接添加到项目中,而是供其他模块引用时进行版本匹配和管理。
-
<build>
、<plugins>
和<plugin>
:<build>
元素用于定义 Maven 构建的各种配置,例如源代码目录、资源目录、插件配置等。它是一个容器元素,可以包含多个子元素,如<plugins>
、<resources>
、<testResources>
等。<plugins>
元素是<build>
元素下的子元素,用于列出构建过程中使用的插件。每个<plugin>
元素定义一个特定的插件,并配置其行为、目标、执行阶段等。<plugin>
元素是<plugins>
元素下的子元素,用于定义一个特定的插件及其相关配置,包括插件的坐标(groupId、artifactId 和 version)、目标(goals)、配置参数等。
总结:
<dependencies>
和<dependency>
用于列出项目的依赖项。<dependencyManagement>
用于集中管理依赖项的版本信息。<build>
是用于定义 Maven 构建配置的容器元素。<plugins>
和<plugin>
用于定义和配置构建过程中使用的插件。