英文:
how to access a shadowed gradle property
问题
如何访问在当前上下文中被其他属性遮盖的Gradle属性变量?
示例:
gradle.properties
version = 1.0
someOtherVar = test
build.gradle
apply plugin 'java'
jar {
archiveVersion = "${version}-${someOtherVar}"
}
在这种情况下,${version}
引用的是 jar.version 而不是具有相同名称的属性(属性 version 被 jar version 遮盖)。如何在 jar
上下文中获取 version 属性的值?
英文:
How can I access a gradle property variable that is shadowed by some other property in the current context?
Example:
gradle.properties
version = 1.0
someOtherVar = test
build.gradle
apply plugin 'java'
jar {
archiveVersion = "${version}-${someOtherVar}"
}
In that context ${version}
refers to the jar.version instead of the property having the same name (property version is shadowed by jar version). How can I get the value of the version property in the jar
context?
答案1
得分: 0
项目的 version
字段可以通过 FQN project.version
(对于当前项目)或 rootProject.version
(对于根项目)访问。
英文:
The project's version
fields can be accessed via the FQN project.version
(for the current project) or rootProject.version
(for the root project).
答案2
得分: 0
在这种特定情况下,您可以使用Project.version属性,但在更一般的情况下,请使用Project.property(propertyName)方法:
apply plugin 'java'
jar {
archiveVersion = "${property('version')}-${someOtherVar}"
}
英文:
While in this specific case, you could use the Project.version property, in a more general case, use the Project.property(propertyName) method:
apply plugin 'java'
jar {
archiveVersion = "${property('version')}-${someOtherVar}"
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论