一、Maven的pom.xml
Maven是基于项目对象模型的概念运行的。所有Maven的项目都有一个pom.xml用来管理项目的依赖以及项目的编译等功能。
- dependencies元素
,此元素包含多个项目依赖,每个依赖需要用
元素来配置。
2.dependency元素
内部通过groupId,artifactId以及version确定唯一的依赖。groupId是组织的唯一标识,artifactId是项目的唯一标识,version是项目的版本。
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
3.变量定义
可定义变量在中使用。比如上例中的元素中的变量就是pom.xml开始的元素中所定义的。
<properties>
<mybatis.spring.boot.version>1.3.0</mybatis.spring.boot.version>
</properties>
4.编译插件
Maven 提供了编译插件,可在编译插件中涉及java的编译级别。
二、Maven仓库
Maven仓库用来存放Maven管理的所有Jar包。当项目需要jar包的时候通过坐标去仓库寻找jar包。分为:本地仓库、私服公司的仓库)和中央仓库。
当项目编译时,Maven首先从本地仓库中寻找项目所需的Jar包,若本地仓库没有,再到Maven的私服或中央仓库下载所需Jar包。
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<!--阿里云Maven仓库-->
<repositories>
<repository>
<id>aliyun-repos</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>aliyun-plugin</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<pluginRepositories>
<pluginRepository>
<id>tomcat8-plugin</id>
<url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
</pluginRepository>
</pluginRepositories>
三、传递依赖与排除依赖
传递依赖:如果我们的项目引用了一个Jar包,而该Jar包又引用了其他Jar包,那么在默认情况下项目编译时,Maven会把直接引用和间接引用的Jar包都下载到本地。
排除依赖:如果不想引用间接引用的Jar包,那么可以在pom.xml中做exclusion配置
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 排除内置容器,排除内置容器导出成war包可以让外部容器运行spring-boot项目-->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
四、生成项目站点报告
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<locales>zh_CN</locales>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</build>

生成结果
五、常见问题
-
乱码解决:
乱码解决
MAVEN_OPTS:-Xms128m -Xmx512m -Dfile.encoding=UTF-8
JAVA_TOOL_OPTIONS:-Dfile.encoding=UTF-8
- 解決 IDEA Create Maven Project 卡在 Downloading plugins for
maven每次进行创建的时候回去网上下载artheType-catalog.xml
