一个新建项目的完整 POM 示例如下:

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0"
    3. 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. <modelVersion>4.0.0</modelVersion>
    6. <groupId>nxcloud.sample</groupId>
    7. <artifactId>sample-parent</artifactId>
    8. <version>1.0.0-SNAPSHOT</version>
    9. <modules>
    10. <module>sample-entity</module>
    11. <module>sample-domain</module>
    12. <module>sample-provider</module>
    13. </modules>
    14. <packaging>pom</packaging>
    15. <name>${project.artifactId}</name>
    16. <repositories>
    17. <!-- 按照项目实际情况配置 -->
    18. <repository>
    19. <id>nxcloud-public</id>
    20. <name>Public Repositories</name>
    21. <url>http://.../repository/maven-public/</url>
    22. </repository>
    23. <repository>
    24. <id>central</id>
    25. <name>Maven Central</name>
    26. <url>https://maven.aliyun.com/repository/public/</url>
    27. </repository>
    28. </repositories>
    29. <pluginRepositories>
    30. <pluginRepository>
    31. <id>central</id>
    32. <name>Maven Central</name>
    33. <url>https://maven.aliyun.com/repository/public/</url>
    34. </pluginRepository>
    35. </pluginRepositories>
    36. <distributionManagement>
    37. <repository>
    38. <id>nxcloud-releases</id>
    39. <name>NXCloud Releases</name>
    40. <url>http://.../repository/maven-releases/</url>
    41. </repository>
    42. <snapshotRepository>
    43. <id>nxcloud-snapshots</id>
    44. <name>NXCloud Snapshots</name>
    45. <url>http://.../repository/maven-snapshots/</url>
    46. </snapshotRepository>
    47. </distributionManagement>
    48. <profiles>
    49. <profile>
    50. <id>local</id>
    51. <properties>
    52. <gm.jar.profile>local</gm.jar.profile>
    53. <gm.jar.version>1.0.0-SNAPSHOT</gm.jar.version>
    54. </properties>
    55. <activation>
    56. <property>
    57. <name>gm.build.type</name>
    58. <value>local</value>
    59. </property>
    60. <activeByDefault>true</activeByDefault>
    61. </activation>
    62. </profile>
    63. <profile>
    64. <id>dev</id>
    65. <properties>
    66. <gm.jar.profile>dev</gm.jar.profile>
    67. <gm.jar.version>1.0.0-SNAPSHOT</gm.jar.version>
    68. </properties>
    69. <activation>
    70. <property>
    71. <name>gm.build.type</name>
    72. <value>dev</value>
    73. </property>
    74. </activation>
    75. </profile>
    76. <profile>
    77. <id>qa</id>
    78. <properties>
    79. <gm.jar.profile>qa</gm.jar.profile>
    80. <gm.jar.version>5.0.0-SNAPSHOT</gm.jar.version>
    81. </properties>
    82. <activation>
    83. <property>
    84. <name>gm.build.type</name>
    85. <value>qa</value>
    86. </property>
    87. </activation>
    88. </profile>
    89. <profile>
    90. <id>prod</id>
    91. <properties>
    92. <gm.jar.profile>prod</gm.jar.profile>
    93. <gm.jar.version>9.0.0-SNAPSHOT</gm.jar.version>
    94. </properties>
    95. <activation>
    96. <property>
    97. <name>gm.build.type</name>
    98. <value>prod</value>
    99. </property>
    100. </activation>
    101. </profile>
    102. </profiles>
    103. <properties>
    104. <maven.compiler.source>8</maven.compiler.source>
    105. <maven.compiler.target>8</maven.compiler.target>
    106. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    107. <!-- 插件版本 -->
    108. <plugin.maven.jar.version>3.2.0</plugin.maven.jar.version>
    109. <plugin.maven.compiler.version>3.8.1</plugin.maven.compiler.version>
    110. <plugin.maven.source.version>3.2.1</plugin.maven.source.version>
    111. <plugin.maven.javadoc.version>3.2.0</plugin.maven.javadoc.version>
    112. <plugin.maven.deploy.version>3.0.0-M1</plugin.maven.deploy.version>
    113. <plugin.maven.war.version>3.3.1</plugin.maven.war.version>
    114. <plugin.maven.surefire.version>3.0.0-M5</plugin.maven.surefire.version>
    115. <plugin.maven.failsafe.version>3.0.0-M5</plugin.maven.failsafe.version>
    116. <plugin.maven.assembly.version>3.3.0</plugin.maven.assembly.version>
    117. <plugin.maven.enforcer.version>3.0.0-M3</plugin.maven.enforcer.version>
    118. <plugin.maven.clean.version>3.1.0</plugin.maven.clean.version>
    119. <plugin.maven.dependency.version>3.1.2</plugin.maven.dependency.version>
    120. <plugin.codehaus.build.helper.version>3.2.0</plugin.codehaus.build.helper.version>
    121. <plugin.mybatis.generator.version>1.4.0</plugin.mybatis.generator.version>
    122. <plugin.spring.boot.version>2.4.2</plugin.spring.boot.version>
    123. <plugin.fabric8.docker.version>0.34.1</plugin.fabric8.docker.version>
    124. </properties>
    125. <dependencyManagement>
    126. <dependencies>
    127. <dependency>
    128. <groupId>nxcloud.foundation</groupId>
    129. <artifactId>nxcloud-dependencies</artifactId>
    130. <version>${gm.jar.version}</version>
    131. <type>pom</type>
    132. <scope>import</scope>
    133. </dependency>
    134. <!-- current project 方便子模块使用 -->
    135. <dependency>
    136. <groupId>${project.groupId}</groupId>
    137. <artifactId>sample-entity</artifactId>
    138. <version>${project.version}</version>
    139. </dependency>
    140. <dependency>
    141. <groupId>${project.groupId}</groupId>
    142. <artifactId>sample-domain</artifactId>
    143. <version>${project.version}</version>
    144. </dependency>
    145. <dependency>
    146. <groupId>${project.groupId}</groupId>
    147. <artifactId>sample-provider</artifactId>
    148. <version>${project.version}</version>
    149. </dependency>
    150. </dependencies>
    151. </dependencyManagement>
    152. <dependencies>
    153. <dependency>
    154. <groupId>org.projectlombok</groupId>
    155. <artifactId>lombok</artifactId>
    156. </dependency>
    157. <dependency>
    158. <groupId>org.junit.jupiter</groupId>
    159. <artifactId>junit-jupiter-api</artifactId>
    160. </dependency>
    161. <dependency>
    162. <groupId>org.junit.jupiter</groupId>
    163. <artifactId>junit-jupiter-engine</artifactId>
    164. </dependency>
    165. <dependency>
    166. <groupId>org.junit.platform</groupId>
    167. <artifactId>junit-platform-commons</artifactId>
    168. </dependency>
    169. </dependencies>
    170. <build>
    171. <pluginManagement>
    172. <plugins>
    173. <plugin>
    174. <groupId>org.apache.maven.plugins</groupId>
    175. <artifactId>maven-jar-plugin</artifactId>
    176. <version>${plugin.maven.jar.version}</version>
    177. </plugin>
    178. <plugin>
    179. <groupId>org.apache.maven.plugins</groupId>
    180. <artifactId>maven-compiler-plugin</artifactId>
    181. <version>${plugin.maven.compiler.version}</version>
    182. </plugin>
    183. <plugin>
    184. <groupId>org.apache.maven.plugins</groupId>
    185. <artifactId>maven-source-plugin</artifactId>
    186. <version>${plugin.maven.source.version}</version>
    187. </plugin>
    188. <plugin>
    189. <groupId>org.apache.maven.plugins</groupId>
    190. <artifactId>maven-javadoc-plugin</artifactId>
    191. <version>${plugin.maven.javadoc.version}</version>
    192. </plugin>
    193. <plugin>
    194. <groupId>org.apache.maven.plugins</groupId>
    195. <artifactId>maven-deploy-plugin</artifactId>
    196. <version>${plugin.maven.deploy.version}</version>
    197. </plugin>
    198. <plugin>
    199. <groupId>org.apache.maven.plugins</groupId>
    200. <artifactId>maven-war-plugin</artifactId>
    201. <version>${plugin.maven.war.version}</version>
    202. </plugin>
    203. <plugin>
    204. <groupId>org.apache.maven.plugins</groupId>
    205. <artifactId>maven-surefire-plugin</artifactId>
    206. <version>${plugin.maven.surefire.version}</version>
    207. </plugin>
    208. <plugin>
    209. <groupId>org.apache.maven.plugins</groupId>
    210. <artifactId>maven-failsafe-plugin</artifactId>
    211. <version>${plugin.maven.failsafe.version}</version>
    212. </plugin>
    213. <plugin>
    214. <groupId>org.apache.maven.plugins</groupId>
    215. <artifactId>maven-assembly-plugin</artifactId>
    216. <version>${plugin.maven.assembly.version}</version>
    217. </plugin>
    218. <plugin>
    219. <groupId>org.apache.maven.plugins</groupId>
    220. <artifactId>maven-enforcer-plugin</artifactId>
    221. <version>${plugin.maven.enforcer.version}</version>
    222. </plugin>
    223. <plugin>
    224. <groupId>org.apache.maven.plugins</groupId>
    225. <artifactId>maven-clean-plugin</artifactId>
    226. <version>${plugin.maven.clean.version}</version>
    227. </plugin>
    228. <plugin>
    229. <groupId>org.codehaus.mojo</groupId>
    230. <artifactId>build-helper-maven-plugin</artifactId>
    231. <version>${plugin.codehaus.build.helper.version}</version>
    232. </plugin>
    233. <plugin>
    234. <groupId>org.apache.maven.plugins</groupId>
    235. <artifactId>maven-dependency-plugin</artifactId>
    236. <version>${plugin.maven.dependency.version}</version>
    237. </plugin>
    238. <plugin>
    239. <groupId>org.mybatis.generator</groupId>
    240. <artifactId>mybatis-generator-maven-plugin</artifactId>
    241. <version>${plugin.mybatis.generator.version}</version>
    242. </plugin>
    243. <plugin>
    244. <groupId>org.springframework.boot</groupId>
    245. <artifactId>spring-boot-maven-plugin</artifactId>
    246. <version>${plugin.spring.boot.version}</version>
    247. <executions>
    248. <execution>
    249. <goals>
    250. <goal>repackage</goal>
    251. </goals>
    252. </execution>
    253. </executions>
    254. </plugin>
    255. <plugin>
    256. <groupId>io.fabric8</groupId>
    257. <artifactId>docker-maven-plugin</artifactId>
    258. <version>${plugin.fabric8.docker.version}</version>
    259. </plugin>
    260. </plugins>
    261. </pluginManagement>
    262. <plugins>
    263. <plugin>
    264. <groupId>org.apache.maven.plugins</groupId>
    265. <artifactId>maven-clean-plugin</artifactId>
    266. <executions>
    267. <execution>
    268. <id>auto-clean</id>
    269. <phase>initialize</phase>
    270. <goals>
    271. <goal>clean</goal>
    272. </goals>
    273. </execution>
    274. </executions>
    275. </plugin>
    276. <plugin>
    277. <groupId>org.apache.maven.plugins</groupId>
    278. <artifactId>maven-jar-plugin</artifactId>
    279. <configuration>
    280. <archive>
    281. <addMavenDescriptor>true</addMavenDescriptor>
    282. <index>true</index>
    283. <manifest>
    284. <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
    285. <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
    286. </manifest>
    287. </archive>
    288. </configuration>
    289. </plugin>
    290. <plugin>
    291. <groupId>org.apache.maven.plugins</groupId>
    292. <artifactId>maven-compiler-plugin</artifactId>
    293. </plugin>
    294. </plugins>
    295. <finalName>${project.artifactId}-${gm.jar.version}</finalName>
    296. </build>
    297. </project>