Search code examples
gradlejarpropertiesshadowing

how to access a shadowed gradle property


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?


Solution

  • The project's version fields can be accessed via the FQN project.version (for the current project) or rootProject.version (for the root project).