2015-11-01 89 views
2

我已经创建了几个Spring Boot项目,每个项目的POM都包含一个spring-boot-starter-parent作为父项。无论何时出现新版本,我现在都需要在每个POM中手动更新它。在多个项目中管理Spring Boot父POM版本

添加已经具有了弹簧引导启动父没有帮助,而且Spring Boot documentation指出,使用“进口”范围将依赖关系只是工作,而不是春天引导版本本身就是一个POM依赖。

有没有一种方法可以定义我的所有项目都可以继承的“super-pom”,我可以在其中设置Spring Boot版本一次,而不是通过每个项目?

回答

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,你会发现他们都在那里。

相关问题