More specifically I have a few build configs:
signingConfigs {
debug {
keyAlias ''
keyPassword ''
storeFile file('')
}
release {
keyAlias ''
keyPassword ''
storeFile file('')
storePassword ''
}
}
....
defaultConfig {
applicationId ""
minSdkVersion 21
targetSdkVersion 23
versionCode code
}
I want the gradle to autoincrement code version every time the 'release' is run.
What I have so far:
def code = 1;
//Get all the gradle task names being run
List<String> runTasks = gradle.startParameter.getTaskNames();
for (String item : runTasks) {
//Get the version.properties file. Its our custom file for storing a code version, please don't remove it
def versionPropsFile = file('version.properties')
def Properties versionProps = new Properties()
//This will prevent the gradle from exploding when there's no file yet created
if (versionPropsFile.exists())
versionProps.load(new FileInputStream(versionPropsFile))
//It will insert the "0" version in case the file does not exist
code = (versionProps['VERSION_CODE'] ?: "0").toInteger()
if (item.contains("release")) {
// If we're building up on Jenkins, increment the version strings
code++
versionProps['VERSION_CODE'] = code.toString()
//It will overwrite the file even if it doesn't exist
versionProps.store(versionPropsFile.newWriter(), null)
}
}
The problem:
I can't seem to get inside if (item.contains("release"))
. Its always false but I definitely see that gradle runs this taks. How can I fix it or at least output in console all the tasks (their names) being run by gradle?