I want to use Gradle Release Plugin in Android Project
.
I configured it and everything is okay, except one thing:
Gradle Release Plugin
changes project version in gradle.properties
file in one of its tasks, but this change does not affect Android Project's
versionName
, because as I found with using println()
gradle initialising it before running any tasks.
Is there a way to change Android Project
versionName
in some gradle task after it was initialised?
Here is part of my build.gradle
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 213
versionName version // to change it, please visit gradle.properties file
println('Project version: ' + version) // this line executed BEFORE any gradle task :(
}
...
}
I can see only one solution: different gradle executions
- Will change version in gradle.properties
- Will execute build process, but this is bad workaround especially for
Gradle Release Plugin
Here is a workaround I used which splits the execution of tasks into multiple gradle executions. It works for svn but can be adapted:
https://stackoverflow.com/a/26659974/256770
Since version 2.1.0 the gradle-release plugin is executing the build in a separate process. This ensures the version is correct throughout the build process and for all other plugins which rely on the version being set from the beginning.
see full changelog
Insert this functions in your build.gradle
Disclaimer: I've created this gist.
The complete gist. https://gist.github.com/ascariandrea/9991499