我创建了一些Spring Boot项目,每个项目的POM都包含一个 spring-boot-starter-parent 作为父项。每当新版本发布时,我当前需要在每个POM中手动更新它。
添加已经具有 spring-boot-starter-parent 的POM依赖项无济于事,而Spring Boot documentation表示使用' import' scope只适用于依赖项,而不适用于Spring Boot版本本身。
有没有办法定义一个" super-pom"我的所有项目都可以继承,我可以在哪里设置Spring Boot版本,而不是通过每个项目?
答案 0 :(得分:3)
您可以尝试以下方法。
您的父母POM:
<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>
<!-- Do you really need to have this parent? -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.7.RELEASE</version>
</parent>
<groupId>org.example</groupId>
<artifactId>my-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Parent POM</name>
<properties>
<!-- Change this property to switch Spring Boot version-->
<spring.boot.version>1.2.7.RELEASE</spring.boot.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Declare the Spring Boot dependencies you need here
Please note that you don't need to declare the version tags.
That's the whole point of the import above.
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<!-- About 50 in total if you need them all -->
...
</dependencies>
</project>
儿童POM:
<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>
<parent>
<groupId>org.example</groupId>
<artifactId>my-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>my-child</artifactId>
<name>Child POM</name>
</project>
如果您对儿童POM进行mvn dependency:tree
,您会发现他们都在那里。