gpt4 book ai didi

gradle - 无法在Gradle插件 block 中参数化版本

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

在Gradle中,当我声明具有硬编码版本的插件时,效果很好:

plugins {
id 'org.springframework.boot' version '2.1.4.RELEASE'
}

但是,如果我尝试将其参数化,则会出现异常。
gradle.properties的内容:
springBootVersion=2.1.4.RELEASE
build.gradle的内容:
plugins {
id 'org.springframework.boot' version "$springBootVersion"
}

为什么发生以下异常?
Cause: startup failed:
build file 'build.gradle': 10: argument list must be exactly 1 literal non empty string

See https://docs.gradle.org/5.2.1/userguide/plugins.html#sec:plugins_block for information on the plugins {} block

@ line 10, column 5.
id 'org.springframework.boot' version "$springBootVersion"
^

1 error

最佳答案

您面对的是plugins块的documented limitation。您不能在其中使用参数化。

可能的是将插件版本的配置委派给settings.gradle

gradle.properties中:

springBootVersion=2.1.4.RELEASE

settings.gradle中:
// Must be the first statement of settings.gradle
pluginManagement {
resolutionStrategy {
eachPlugin {
if (requested.id.id == "org.springframework.boot") {
useModule("org.springframework.boot:org.springframework.boot.gradle.plugin:${springBootVersion}")
}
}
}
}

build.gradle中:
plugins {
id 'org.springframework.boot'
}

关于gradle - 无法在Gradle插件 block 中参数化版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55617601/

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