SpringBoot及SpringCloud版本管理(Gradle版本)

前言

  1. 网上有很多介绍SpringBoot和SpringCloud版本对应的文章,本文只是从实操的角度阐述,内容没有深度.

  2. Maven中有dependencyManagement来声明依赖,Gradle中也有相应的功能.

Talk is cheap. Show me the code

build.gradle

plugins {
    id "io.spring.dependency-management" version "1.0.8.RELEASE"
}

dependencyManagement {
    imports {
        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Finchley.SR1'
    }
}

dependencies {
    compile "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client"
}

此时观看gradle依赖,发现自动引入的springboot版本为2.0.4.RELEASE,可以确定springboot的大版本了,同样的方式引入springboot的gradle插件org.springframework.boot,并添加指定父依赖"org.springframework.boot:spring-boot-starter-parent:2.0.4.RELEASE"

最终效果如下:

plugins {
    id "io.spring.dependency-management" version "1.0.8.RELEASE"
    id "org.springframework.boot" version "2.0.4.RELEASE"
}

dependencyManagement {
    imports {
    	// 插件org.springframework.boot已经包含了版本管理功能,这个声明可以不要
        // mavenBom "org.springframework.boot:spring-boot-starter-parent:2.0.4.RELEASE"
        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Finchley.SR1'
    }
}

dependencies {
	testCompile "org.springframework.boot:spring-boot-starter-test"
    compile "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client"
}

思路

先根据SpringCloud版本管理插件确定SpringBoot版本,再根据这个大版本管理其他依赖.

问题

本地使用正常,但是上到环境后经常报无法下载,发现是新版gradle插件引入方式导致的,它默认从gradle官网拉取,而官网不稳定.
解决办法:
在项目根目录下的settings.gradle中指定插件仓库

pluginManagement {
    resolutionStrategy {
    }
    repositories {
        maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
        gradlePluginPortal()
    }
}

Tips

如果使用了插件id "org.springframework.boot" version "2.0.4.RELEASE",那么会自动将springboot大版本设置为2.0.4.RELEASE,dependencyManagement任务中的mavenBom "org.springframework.boot:spring-boot-starter-parent:${springBootVersion}"就可以不要了.

参考

https://plugins.gradle.org/plugin/io.spring.dependency-management

https://stackoverflow.com/questions/38221227/gradle-configuration-of-pluginrepository

https://www.coder4.com/archives/5884

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值