我是新手,对项目属性有一些疑问。
我需要在build.gradle的多个位置声明spring boot的依赖关系,我想使用一个变量来定义版本。最好的方式是gradle? (在Maven中,我使用属性)
我的尝试是使用额外的属性,但无法访问buildscript闭包中的属性。我在Google周围搜索并阅读了许多有关访问自定义任务中属性的文章。我错过了什么?
ext {
springBootVersion = '1.1.9.RELEASE'
}
buildscript {
print project.springBootVersion //fails here
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.springBootVersion}")
}
}
install {
repositories.mavenInstaller {
pom.project {
parent {
groupId 'org.springframework.boot'
artifactId 'spring-boot-starter-parent'
version "${project.springBootVersion}" //this one works
}
}
}
}
最佳答案
将ext
块移到buildscript
块内可以为我解决问题。但不确定是否已正式支持此功能,因为它可以从(非常特殊的)project.ext
块中有效配置buildscript
。
关于gradle - 在buildscript闭包中访问项目的额外属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40294552/