在maven标签中有一个标签是dependencyManagement,他表示对依赖的管理,而不注入依赖。
下面我们定义了依赖的版本
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.6.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.6.2</version>
</dependency>
</dependencies>
</dependencyManagement>
再具体引入依赖的时候我们就可以不用写版本号,这在对多个项目共同引入一个依赖统一版本号有巨大作用
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
</dependency>
我们也可以在dependencyManagement管理依赖排除子依赖使用exclusions
<dependencyManagement>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.6.2</version>
<exclusions>
<exclusion>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencyManagement>