我的构建脚本之一导入了该星云插件:
plugins {
id 'nebula.ospackage' version '3.5.0'
}我一直在将我的所有版本信息移动到一个所有项目都可以访问的单独文件中,我想知道什么是正确的语法来转换成如下所示:
plugins {
id 'nebula.ospackage' version "$versions.nebula_gradle_ospackage_plugin"
}当我尝试使用"gradle clean“运行上面的代码时,我会得到以下错误:
构建文件'build.gradle':2:参数列表必须恰好是一个文字非空字符串 有关插件{}块的信息,请参见区块 @第2行,第33栏。id 'nebula.ospackage‘版本"$versions.nebula_gradle_ospackage_plugin“
链接的文章展示了如何使用"buildscript“块,它可以工作,但似乎必须有一种方法,使这个工作在一个单行?
发布于 2019-11-04 10:28:28
从第5.6级开始,您可以在gradle.properties文件中声明插件版本,并在plugins块中引用这些属性。
例如,gradle.properties文件:
springBootVersion=2.2.0.RELEASEplugins块在build.gradle中:
plugins {
id "org.springframework.boot" version "${springBootVersion}"
}见:https://github.com/gradle/gradle/issues/1697#issuecomment-506910915。
另请参阅:
发布于 2016-06-10 13:21:55
您不能在这里使用变量:
其中插件版本和插件id必须是常量的,文字的,字符串。不允许使用其他语句;它们的存在将导致编译错误。
发布于 2018-10-04 09:47:56
这是一个旧的帖子,但臭虫仍然是开放的,我找到了这个帖子寻找解决办法。
似乎你已经意识到了这一点,而且实际上已经拥有了BoygeniusDexter的回答,但我认为这可能会帮助其他人像我一样找到这篇文章。下面的解决方案基于Gradle博士并为我解决了这个问题:
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id 'java'
// and other plugins
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
}
// but the one with the variable version is applied the old way:
apply plugin: 'org.springframework.boot'
// We can use the variable in dependencies, too:
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
// ...
}https://stackoverflow.com/questions/37555196
复制相似问题