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

标签 spring-boot gradle build.gradle

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

相关文章:

gradle - Gradle测试任务使用 `java.lang.IllegalArgumentException`给出初始化错误?

jsp - 使用 Spring Boot 的 struts2 - JSP 未呈现

java - 自定义排序 SQL hibernate Spring boot 2

javascript - spring boot中的jquery,CORS问题

java - Java如何获取gradle依赖

gradle - kotlin + gradle + intellij-未定义存储库

gradle - 将项目资源添加到Gradle Custom插件

android - 在高层次上,gradle sync 在 Android 中如何工作?

java - 让 Spring 在 rest 调用中接受 UTF-8 字符

java - SocketImpl 和 JUnit/Gradle