maven-bom
maven 有 bom(bills of materials) 功能,bom定义了一套互相兼容的jar包集合。项目只需要依赖bom,即可放心使用依赖的包,无需再指定版本号。
使用dependencyManagement
定义bom,创建一个标准的bom项目如下:
<?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>com.jlcx.qd</groupId>
<artifactId>inf-bom</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring.boot.version>1.5.6.RELEASE</spring.boot.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.4</version>
</dependency>
</dependencies>
</dependencyManagement>
<!-- 私服配置,用于bom发布 -->
<distributionManagement>
<repository>
<id>maven-releases</id>
<name>maven-releases</name>
<url>http://mvn.ydj.com/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<name>maven-snapshots</name>
<url>http://mvn.ydj.com/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
packaging不一定是pom,也可以是jar和war。通常在子项目中引入bom,无需指定版本号。 maven的使用方法,在子项目中通过dependencyManagement引入。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.jlcx.qd</groupId>
<artifactId>inf-bom</artifactId>
<version>0.0.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
...
</dependency>
</dependencies>
</dependencyManagement>
gradle的使用方法:
// import bom
dependencyManagement {
imports {
mavenBom 'com.jlcx.qd:inf-bom:0.0.1'
}
}