The solution I found implies mapping the things you have in your other.gradle
file.
def getVersionName = { testParam ->
println "${testParam}"
def stdout = new ByteArrayOutputStream()
exec {
commandLine git , describe , --tags
standardOutput = stdout
}
return stdout.toString().trim()
}
ext{
VERConsts = [:]
VERConsts[ NAME ] = getVersionName("test param")
VERConsts[ NAME_CALL ] = getVersionName
}
Then, in your build.gradle
file:
apply from: other.gradle
// ...
android {
defaultConfig {
versionName VERConsts[ NAME_CALL ]("test param")
// or
versionName VERConsts[ NAME ]
}
}
Then, the versionName
will have the call result.
Notes:
VERConsts[ NAME ] = getVersionName()
will call getVersionName()
and store its result. Using it in your script e.g. versionName VERConsts[ NAME ]
will then assign the stored value.
VERConsts[ NAME_CALL ]
will instead store a reference to the function. Using VERConsts[ NAME_CALL ]()
in your script will actually call the function and assign the result to your variable
The former will result in the same value being assigned across the script while the latter may result in different values (e.g. if someone pushes another version while your script is running).