Slackbot
03/28/2022, 2:01 PMjoschi
03/28/2022, 2:02 PMLouis Jacomet
03/28/2022, 2:16 PMProvider chain, starting at the most important one and then do a Provider.orElse chain.joschi
03/28/2022, 4:31 PMRegularFileProperty and checking that the files (don't) exist?
I think something like this wouldn't work, would it?
def myVersion = project.objects.fileProperty().fileValue(project.file("specific"))
.orElse(project.objects.fileProperty().fileValue(project.file("global")))
.map(file -> "read version string from file")
.orElse("default")Louis Jacomet
03/28/2022, 4:34 PMjoschi
03/29/2022, 10:21 AMext {
def env = providers.environmentVariable("MY_VERSION")
def specificFile = providers.fileContents(layout.projectDirectory.file("specific")).asText
def globalFile = providers.fileContents(layout.projectDirectory.file("global")).asText
myVersion = env.orElse(specificFile.orElse(globalFile)).getOrElse("default")
}
tasks.register('printVersion') {
it.doLast {
project.println(myVersion)
}
}
Example:
# MY_VERSION=env ./gradlew -q printVersion
env
# ./gradlew -q printVersion
specific
# rm specific && ./gradlew -q printVersion
global
# rm global && ./gradlew -q printVersion
default