无法升级gradle中的春季启动版本



我在本地安装了gradle4.7,下面是我的gradle.build,它运行良好。gradle插件4.7版成功构建了gradle

buildscript {
ext {
springBootVersion = '1.5.2.RELEASE'
}
repositories {
maven { url "https://artifactory.domain.com/mavenrepo" }
maven { url "https://artifactory.domain.com/maven.atlassian.com-cache" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.6"
}
}

apply plugin: "com.github.sherter.google-java-format"
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

apply plugin: 'findbugs'
apply plugin: 'maven-publish'

group = 'com.domain.xyz.myapp'
version = '1.0.1-SNAPSHOT'

repositories {
maven { url "https://artifactory.domain.com/mavenrepo" }
}
project.tasks.findAll { it.name.startsWith("publish") } .each { it.dependsOn assemble }

springBoot {
classifier = 'boot'
}

publishing {
publications {
maven(MavenPublication) {
artifact ("$buildDir/libs/$project.name-$version-boot.jar") {
classifier = 'boot'
}
}
}

repositories {
maven {
url "http://artifactory.xyz.com:8080/project-snapshots"
credentials {
username = "publish-username"
password = "publish-password"
}
}
}
}


tasks.withType(FindBugs) {
reports {
xml.enabled false
html.enabled true
}
}

configurations {
all*.exclude group: 'javax.servlet', module: 'servlet-api'
}

dependencies {
compileOnly('org.projectlombok:lombok:1.16.14')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-cache')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-ldap')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-batch')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework:spring-web')
compile('com.google.guava:guava:r05')
runtime('mysql:mysql-connector-java:8.0.16')
runtime('org.hsqldb:hsqldb:2.3.3')
runtime('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('com.jayway.jsonpath:json-path')
compile('com.jcraft:jsch:0.1.53')
compile('net.sourceforge.jtds:jtds:1.3.1')
compile('jcifs:jcifs:1.3.17')
compile('org.apache.camel:camel-core:2.15.0')
compile('com.github.ulisesbocchio:jasypt-spring-boot-starter:1.9')
compile('io.micrometer:micrometer-registry-prometheus:1.0.3')
compile('io.micrometer:micrometer-spring-legacy:1.0.3')
}

当我运行gradle build时,它运行良好。

但现在我需要将SpringBootVersion升级到2.4.3(最新版本(,并将文件中的第三行替换为:

springBootVersion = '2.4.3'

但我得到以下错误:

未能应用插件[id'org.springframework.boot']Spring boot插件需要Gradle 5(仅5.6.x(或Gradle 6(6.3或更高版本(。这个目前的版本是4.7级

如果gradle build在4.7中运行良好,那么4.7中的apply plugin: 'org.springframework.boot'行也很好,4.7可以识别它,为什么它会要求我升级到更高的版本,而4.7可以构建它?我错过了什么?如何正确升级Spring Boot版本并解决它?

您将需要更新gradle,因为较新的春季启动版本与较旧版本的gradle不兼容。

您可以手动下载新的渐变,也可以使用渐变包装器为您的项目设置版本。

您可以使用命令来完成此操作

gradle wrapper --gradle-version 6.8.3./gradle wrapper --gradle-version 6.8.3

有时gradle的版本太旧,无法进行更新跳跃,无论如何你都必须手动下载新版本(如果我没记错的话,gradle 2可能太旧,不能直接进入6。(

要在设置好包装器后使用它,只需将gradle命令替换为gradlew即可。示例:

gradlew bootRun

在buildScript块中,您有以下代码行:

classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")

这是告诉gradle使用哪个版本的spring-boot插件的代码。当您将springBootVersion = '1.5.2.RELEASE'更改为springBootVersion = '2.4.3'时,这也会影响春季启动版本以及春季启动插件版本。因此出现了错误。

最新更新