我有这个build.gradle
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
id 'eclipse-wtp'
}
[...]
dependencies {
compileOnly group: 'org.springframework.boot', name: 'spring-boot-dependencies', version: '2.1.6.RELEASE', ext: 'pom'
[...]
我会指定一个变量
springBootVersion = "2.1.6.RELEASE"
.不幸的是,这是不可能的,因为我收到了这个错误:only buildscript {} and other plugins {} script blocks are allowed before plugins {} blocks
我还尝试从
spring-boot-dependencies
中删除版本但我收到此错误:Could not resolve: org.springframework.boot:spring-boot-dependencies
有没有办法在
plugin{}
之前声明一个变量?阻止,或者,从 spring-boot-dependencies
中删除版本?我正在使用 Gradle 5.4.1
最佳答案
您不能在插件 block 中使用变量。在此处检查“严格语法”部分:https://docs.gradle.org/current/javadoc/org/gradle/plugin/use/PluginDependenciesSpec.html
还:
https://github.com/gradle/gradle/issues/3593
除了插件 block 之外,您不需要在任何其他地方定义 spring boot 版本,方法是应用 spring boot 插件(org.springframework.boot),然后在 block 之后应用(io.spring.dependency-management)。后者将负责根据引导插件版本解析正确的版本。
如果还不知道,建议使用https://start.spring.io/生成你的 spring boot 项目,因为它可以为你生成一个现成的 gradle 项目。
关于spring-boot - 无法在插件之前设置变量{},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57055430/