gpt4 book ai didi

spring-boot - 无法在插件之前设置变量{}

转载 作者:行者123 更新时间:2023-12-03 05:34:45 25 4
gpt4 key购买 nike

我有这个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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com