Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a maven BOM for Spring in Gradle?

I am converting POM to Gradle and one of the things I am stuck at is having dependency management in Gradle like the following that I have in POM:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Edgware.SR4</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Is there a way to have Edgware.SR4 in Gradle as well?

I checked https://docs.gradle.org/4.6/release-notes.html#bom-import but that doesn't really tell me a way on how to utilize Edgware.SR4 BOM.


UPDATE

I finally have my build.gradle as follows that seems to work:

plugins{
   id 'org.springframework.boot' version '1.5.8.RELEASE'
}

apply plugin: 'io.spring.dependency-management'
dependencyManagement {
    imports {
       mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Edgware.SR4'
    }
}

This seems to be working fine but wondering if there is any flaw in this approach. Documentation available at https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/ suggests to use apply false to begin with in

id 'org.springframework.boot' version '1.5.8.RELEASE'

I didn't do that and it worked fine. Wondering why it was suggested like that.

like image 840
Ray S Avatar asked Dec 04 '18 19:12

Ray S


Video Answer


1 Answers

Assuming that you are using Spring Boot and, therefore, already have the Dependency Management Plugin applied, you can import Spring Cloud's bom by adding the following to your build.gradle file:

dependencyManagement {
    imports {
        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Edgware.SR4'
    }
}
like image 155
Andy Wilkinson Avatar answered Oct 03 '22 03:10

Andy Wilkinson