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

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5.  
  6. <!--pom版本-->
  7. <modelVersion>4.0.</modelVersion>
  8.  
  9. <!--项目坐标-->
  10. <groupId>cn.itcast.account.mvnbook</groupId>
  11. <artifactId>account</artifactId>
  12. <version>1.0-SNAPSHOT</version>
  13. <packaging>pom</packaging>
  14.  
  15. <!--聚合模块-->
  16. <modules>
  17. <module>accounte-mail</module>
  18. <module>account-api</module>
  19. </modules>
  20.  
  21. <!--参数管理-->
  22. <properties>
  23. <spring.version>5.1..RELEASE</spring.version>
  24. <mybatis.version>3.5.</mybatis.version>
  25. <mybatis-spring.version>2.0.</mybatis-spring.version>
  26. <mail.version>1.4.</mail.version>
  27. <greenmail.version>1.5.</greenmail.version>
  28. <junit.version>4.12</junit.version>
  29. <maven-compile-plugin.version>3.8.</maven-compile-plugin.version>
  30. <jdk.version>1.8</jdk.version>
  31. </properties>
  32.  
  33. <!--仓库管理,即去哪个远程仓库下载依赖-->
  34. <repositories>
  35. <!--正式版本-->
  36. <repository>
  37. <id>releases</id>
  38. <url>http://</url>
  39. </repository>
  40. <!--快照版本-->
  41. <repository>
  42. <id>snapshots</id>
  43. <url>http://</url>
  44. </repository>
  45. </repositories>
  46.  
  47. <!--部署管理,即将项目作为构件部署到哪个远程仓库-->
  48. <distributionManagement>
  49. <!--正式版本-->
  50. <repository>
  51. <id>releases</id>
  52. <url>http://</url>
  53. </repository>
  54. <!--快照版本-->
  55. <snapshotRepository>
  56. <id>snapshots</id>
  57. <url>http://</url>
  58. </snapshotRepository>
  59. </distributionManagement>
  60.  
  61. <!--依赖管理,子模块可以选择性继承-->
  62. <dependencyManagement>
  63. <dependencies>
  64. <!--spring starts-->
  65. <dependency>
  66. <groupId>org.springframework</groupId>
  67. <artifactId>spring-core</artifactId>
  68. <version>${spring.version}</version>
  69. </dependency>
  70. <dependency>
  71. <groupId>org.springframework</groupId>
  72. <artifactId>spring-beans</artifactId>
  73. <version>${spring.version}</version>
  74. </dependency>
  75. <!--spring ends-->
  76. <!--mybatis starts-->
  77. <dependency>
  78. <groupId>org.mybatis</groupId>
  79. <artifactId>mybatis</artifactId>
  80. <version>${mybatis.version}</version>
  81. </dependency>
  82. <dependency>
  83. <groupId>org.mybatis</groupId>
  84. <artifactId>mybatis-spring</artifactId>
  85. <version>${mybatis-spring.version}</version>
  86. </dependency>
  87. <!--mybatis ends-->
  88. <!--mail starts-->
  89. <dependency>
  90. <groupId>javax.mail</groupId>
  91. <artifactId>mail</artifactId>
  92. <version>${mail.version}</version>
  93. </dependency>
  94. <dependency>
  95. <groupId>com.icegreen</groupId>
  96. <artifactId>greenmail</artifactId>
  97. <version>${greenmail.version}</version>
  98. <scope>test</scope>
  99. </dependency>
  100. <!--mail ends-->
  101. <!--test starts-->
  102. <dependency>
  103. <groupId>junit</groupId>
  104. <artifactId>junit</artifactId>
  105. <version>${junit.version}</version>
  106. <scope>test</scope>
  107. </dependency>
  108. <!--test ends-->
  109. </dependencies>
  110. </dependencyManagement>
  111.  
  112. <!--项目构建管理-->
  113. <build>
  114. <!--插件管理,子模块可以选择性继承-->
  115. <pluginManagement>
  116. <plugins>
  117. <plugin>
  118. <groupId>org.apache.maven.plugins</groupId>
  119. <artifactId>maven-compiler-plugin</artifactId>
  120. <version>${maven-compile-plugin.version}</version>
  121. <configuration>
  122. <source>${jdk.version}</source>
  123. <target>${jdk.version}</target>
  124. </configuration>
  125. </plugin>
  126. </plugins>
  127. </pluginManagement>
  128. </build>
  129.  
  130. </project>

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

  1. <servers>
    <!--id必须与pom文件中的repositories标签中设置的一致-->
  2. <server>
  3. <id>releases</id>
  4. <username>admin</username>
  5. <password>admin123</password>
  6. </server>
  7. <server>
  8. <id>snapshots</id>
  9. <username>admin</username>
  10. <password>admin123</password>
  11. </server>
  12. </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. 使用Log4Net将系统日志信息记录到记事本和数据库中

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/hxpjava1/article/details/32714855 一.使用Log4Net将日志记录到 ...

  2. 开发jquery插件小结

    用jquery开发插件其实很简单.今天实现了一个入门级别的功能. 随便来个DIV,便于理解. div{ height:100px;width:100px;display:block;backgroun ...

  3. TMS320F28335——下载程序到flash中

    一.让CCS软件支持Flash烧写 添加F28335.cmd文件 如图屏蔽掉25335_RAM_lnk.cmd 2.支持从Flash中拷贝文件到RAM中 添加DSP2832x_MemCopy.c 在主 ...

  4. 在Python中使用protobuf2.6.1 string format utf-8 and unicode error

    版本信息: protobuf: v2.6.1 python: 2.7 关于在Python中使用protobuf时 string格式字段的编码问题 在python中编码格式多采用utf-8格式.而pro ...

  5. redis基础及redis特殊场景使用描述

    数据类型 String set list hash zset redis原理 单线程:redis是单线程+io多路复用:检查文件描述的就绪状态 对比memchached:多线程+锁 redis优势 解 ...

  6. PowerEdge T630服务器安装机器学习环境(Ubuntu18.04、Nvidia 1080Ti驱动、CUDA及CUDNN安装)

    安装步骤 在开始安装之前,我要说明一下,这个Ubuntu18.04系统的安装,使用的连接线(就是服务器和电脑显示器的连接线)必须两头都是VGA连接线,不能使用VGA转HDMI连接线,也不能用DVI转D ...

  7. SVN本地搭建服务

    本地搭建svn 服务端并使用 1.下载SVN服务端软  VisualSVN server 地址:http://subversion.apache.org/packages.html 2.安装 Visu ...

  8. thymeleaf常用模板方法收集

    判断是不是为空1.th:if="${xxx} != null" th:if="${xxx != null}" 是不是为空字符串 1.th:if="${ ...

  9. Kettle整理

    下载kettle版本 (1)hadoop version 查看hadoop的版本    hadoop2.6 (2)则在data-integration\plugins\pentaho-big-data ...

  10. Mixly-指令

    串口: 向串口监视器输出数据       十进制       Serial.println(ir_item,HEX); 向串口监视器输出数据---十六进制 通信: 接收11脚的红外信号,把接收到的数据 ...