2015-11-01 49 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,你會發現他們都在那裏。

相關問題