一个相对完整的maven配置文件

<?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"> <!--pom版本-->
<modelVersion>4.0.</modelVersion> <!--项目坐标-->
<groupId>cn.itcast.account.mvnbook</groupId>
<artifactId>account</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging> <!--聚合模块-->
<modules>
<module>accounte-mail</module>
<module>account-api</module>
</modules> <!--参数管理-->
<properties>
<spring.version>5.1..RELEASE</spring.version>
<mybatis.version>3.5.</mybatis.version>
<mybatis-spring.version>2.0.</mybatis-spring.version>
<mail.version>1.4.</mail.version>
<greenmail.version>1.5.</greenmail.version>
<junit.version>4.12</junit.version>
<maven-compile-plugin.version>3.8.</maven-compile-plugin.version>
<jdk.version>1.8</jdk.version>
</properties> <!--仓库管理,即去哪个远程仓库下载依赖-->
<repositories>
<!--正式版本-->
<repository>
<id>releases</id>
<url>http://</url>
</repository>
<!--快照版本-->
<repository>
<id>snapshots</id>
<url>http://</url>
</repository>
</repositories> <!--部署管理,即将项目作为构件部署到哪个远程仓库-->
<distributionManagement>
<!--正式版本-->
<repository>
<id>releases</id>
<url>http://</url>
</repository>
<!--快照版本-->
<snapshotRepository>
<id>snapshots</id>
<url>http://</url>
</snapshotRepository>
</distributionManagement> <!--依赖管理,子模块可以选择性继承-->
<dependencyManagement>
<dependencies>
<!--spring starts-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<!--spring ends-->
<!--mybatis starts-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis-spring.version}</version>
</dependency>
<!--mybatis ends-->
<!--mail starts-->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>${mail.version}</version>
</dependency>
<dependency>
<groupId>com.icegreen</groupId>
<artifactId>greenmail</artifactId>
<version>${greenmail.version}</version>
<scope>test</scope>
</dependency>
<!--mail ends-->
<!--test starts-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!--test ends-->
</dependencies>
</dependencyManagement> <!--项目构建管理-->
<build>
<!--插件管理,子模块可以选择性继承-->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compile-plugin.version}</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build> </project>

其中,repositories标签的作用是设置远程仓库。Maven项目需要构件(例如jar包)时,会首先去本地仓库中查找。如果本地仓库中不存在,会去远程仓库下载。如果这里不配置repositories,由于所有的pom文件都继承自超级POM,会默认去中央仓库中下载,效率比较低。为了提高效率,在repositories标签中设置私服,当本地仓库中不存在某个构件时,Maven会首先从私服中获取。如果私服中依然不存在,再从外部的远程仓库(例如中央仓库)下载,缓存在私服,供以后局域网用户使用。注意,如果私服设置了权限验证,需要在Maven的setting.xml文件中设置权限校验的参数。

<servers>
<!--id必须与pom文件中的repositories标签中设置的一致-->
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>

modules标签的作用是声明要聚合的模块,在该目录了下执行mvn命令,会一次性执行这里声明的所有被聚合的模块。需要注意的是其子标签module的值应该是目录名称,但通常与被聚合的模块的artifactId一致。

distributionManagement标签的作用是设置项目部署位置,即maven clean deploy命令将项目以构件(例如jar、war、pom等)的形式部署到哪个私服。如果不设置,maven clean deploy命令将无法使用,即无法将项目推送到远程仓库。

dependencyManagement标签的作用是声明项目用到的所有依赖,统一管理依赖的版本等。子模块可以选择性继承这里声明的依赖,只需要设置groupId和artifactId即可,version和scope属性会继承父模块声明的。

pluginManagement标签跟dependencyManagement类似,子模块也可以选择性继承这里声明的插件。

pom.xml文件设置的更多相关文章

  1. 如何在maven pom.xml文件中设置Java编译器版本

    今天遇到一个问题: 在Eclipse中用maven创建一个新的web项目,然后再用maven update一下,则JDK版本自动变为1.5. 通过查找资料,终于发现maven编译器插件(Maven C ...

  2. 史上最全的maven的pom.xml文件详解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  3. Maven项目pom.xml文件详解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  4. 史上最全的maven pom.xml文件教程详解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  5. [maven] pom.xml 文件详解

    参考资料: http://blog.csdn.net/uohzoaix/article/details/7035307 http://www.cnblogs.com/qq78292959/p/3711 ...

  6. Maven中pom.xml文件的配置

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  7. Maven pom.xml文件详解

    Maven pom.xml文件详解 一.简介 POM全称是Project Object Model,即项目对象模型. pom.xml是maven的项目描述文件,它类似与antx的project.xml ...

  8. maven的pom.xml文件详解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  9. maven的pom.xml文件的标签详解

    该博文引至:https://www.cnblogs.com/hafiz/p/5360195.html <project xmlns="http://maven.apache.org/P ...

随机推荐

  1. c# WPF SVG 文件的引用(SharpVectors)

    原文:c# WPF SVG 文件的引用(SharpVectors) 阿里巴巴矢量图标库提供了大量的 SVG 图标:https://www.iconfont.cn/ 但是 WPF 本身不支持 SVG 格 ...

  2. Jpa/Hibernate ManyToOne 关联非主键列 延迟加载失效

    @ManyToOne配置延迟加载,如果是关联主键列, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "billid", ...

  3. OneinStack定时同步备份数据库/网站至七牛云存储方法

    无论我们用WEB面板,还是用一键脚本安装环境建站,只要一旦我们开始用VPS.服务器,最为关键的就是服务器中的数据.因为大部分VPS.服务器商家都是无管理型主机,任何的安装和维护都需要我们自行管理.即便 ...

  4. B/S,C/S架构的区别

    B/S架构:browser/server,采用的是浏览器服务器模式. C/S架构:client/server,采用的是客户端服务器模式. B/S架构,客户端是浏览器基本不需要维护,只需要维护升级服务器 ...

  5. spring服务器接收参数格式

    注:@RequestParam 或@RequestBody等注解是否添加有什么区别 不加:参数可有可无,无参数时为null,但当参数类型是 数字基本类型(int.double)时会报错: 加上@Req ...

  6. 已知链表头结点指针head,写一个函数把这个链表逆序

    Node* ReverseList ( Node *head ) { if ( head == NULL || head->next == NULL ) return head; Node *p ...

  7. CentOS 7 查看硬盘情况

    用命令: lsblk                                  查看分区和磁盘 df -h                                        查看整 ...

  8. test dword ptr [eax],eax ; probe page.局部数组变量定义所分配的最大空间为1M

    问题的出现 使用VS2017编写程序时,程序编译可以通过,但运行时就会弹出错误 经过查证发现: 这跟局部数组变量定义所分配的最大空间设置大小有关. 局部变量的申请空间是存放于栈中,windows里默认 ...

  9. [洛谷P2886] 牛继电器Cow Relays

    问题描述 For their physical fitness program, N (2 ≤ N ≤ 1,000,000) cows have decided to run a relay race ...

  10. c++ printf和cout的性能

    今天做了一道编程题,仔细检查了算法并没有错误,但是结果显示时间超时,但仍有80%的案例通过了,很奇怪. 通过将cin换成scanf,cout换成printf结果AC,实验发现二者性能差了很多,在输出1 ...