Xavier, Thank you for your answer. I'm a little misunderstood with your suggestion: 1. It seems to me that using the env variable for this is bad style and if I use extra property: defaultConfig { minSdkVersion rootProject.minSdkVersion as int targetSdkVersion rootProject.targetSdkVersion as int versionName rootProject.appVersion.toString() versionCode rootProject.appVersionCode } than when should I update these properties? How can I understand, which part of version should be updated before taskGraph is ready?
2. I understand that running tasks in sequence $./gradlew increase*Version saveVersion ... $./gradlew release will solve the problem, but the goal is to release any new version with executing only one command. On Friday, December 12, 2014 9:12:04 PM UTC+3, Xavier Ducrohet wrote: > > It looks like your tasks are changing the model, which is really not what > you want to do. The mode should be considered immutable in the execution > phase. > > We did do change some things with our handling of the version code (to > support splits). What it does now is that when the variants are created, we > merge the flavors (accessible through the variant API), and this is where > we read the version code from. > > So, again, you are changing the model during execution which is too late, > and may or may not work (we actually kind of want to secure this a bit more > in the future, similar to the recent change where the Product Flavor, and > build types in the Variant API are read-only). > > What you should be doing is either: > - inject the version code through an env variable or dynamic project > property > - read version from a file and have another job regularly update the value > in the file. > > On Fri, Dec 12, 2014 at 8:52 AM, Yuri Denison <yuri.d...@gmail.com > <javascript:>> wrote: >> >> Hello. >> I have implemented autoincrement app version feature in my root >> build.gradle >> >> I have 3 release tasks (suppose the base version is 1.0.3): >> release - update version to 2.0.0 and create release apk >> releaseBeta - update version to 1.1.0 and create release apk >> releaseNightly - update version to 1.0.4 and create release apk >> >> Everything worked fine with gradle 1.12 and 0.12.+ plugin. >> After switching to new gradle 2.2.1 and 1.0.0 plugin the problem occurred: >> new apks have old version >> >> Please help me to understand what's wrong with it. >> >> Here is my code: >> - VersionUtils is just helper class to operate with version strings >> >> import java.util.regex.Matcher >> import java.util.regex.Pattern >> >> buildscript { >> repositories { >> jcenter() >> } >> dependencies { >> classpath "com.android.tools.build:gradle:1.0.0" >> } >> } >> >> task wrapper(type: Wrapper) { >> gradleVersion = '2.2.1' >> } >> >> ext { >> deliveryDir = 'delivery' >> appVersion = new Version(project: this, subprojects: subprojects, >> versionName: versionName) >> } >> >> subprojects { >> repositories { >> jcenter() >> } >> } >> >> subprojects.each { subproject -> >> subproject.configurations.all { >> resolutionStrategy.cacheChangingModulesFor 0, 'seconds' >> resolutionStrategy.cacheDynamicVersionsFor 0, 'seconds' >> } >> evaluationDependsOn(subproject.path) >> } >> >> subprojects.findAll { project -> project.hasProperty('android') && >> project.android.hasProperty('applicationVariants') }.each { project -> >> def deliverToLocal = task("deliverToLocal_${project.name}") { >> ext.outputDir = "${deliveryDir}/${project.name}" >> description = "Deliver ${project.name} binaries to ${outputDir} >> folder" >> >> dependsOn project.assembleRelease >> doLast { >> deliverBinariesFor project, outputDir >> } >> } >> >> task("release_${project.name}", dependsOn: deliverToLocal) << { >> description = "Release ${project.name} application" >> } >> } >> >> task clearDeliveryDir << { >> delete deliveryDir >> delete 'build' >> } >> >> def deliverBinariesFor(def project, def outputDir) { >> project.android.applicationVariants.all { variant -> >> copy { >> variant.outputs.each { output -> >> from output.outputFile >> } >> from >> "${project.buildDir}/outputs/proguard/release/mapping.txt" >> from >> "${project.buildDir}/outputs/lint-results-release-fatal.html" >> into outputDir >> } >> copy { >> from("${project.buildDir}/outputs") { >> include 'lint-results*_files/*.css' >> include 'lint-results*_files/*.png' >> } >> into "${outputDir}/lint-result-release-fatal" >> } >> } >> } >> >> task deliverToExternal(dependsOn: [tasks.findAll { task -> task.name. >> startsWith('release_') }]) << {} >> >> //---------------release app--------------------------- >> >> task increaseMajorVersion << { >> appVersion.increaseMajor() >> } >> >> task increaseBetaVersion << { >> appVersion.increaseBeta() >> } >> >> task increaseNightlyVersion << { >> appVersion.increaseNightly() >> } >> >> task saveVersion << { >> appVersion.save() >> } >> >> clearDeliveryDir.mustRunAfter increaseMajorVersion >> clearDeliveryDir.mustRunAfter increaseBetaVersion >> clearDeliveryDir.mustRunAfter increaseNightlyVersion >> deliverToExternal.mustRunAfter clearDeliveryDir >> saveVersion.mustRunAfter deliverToExternal >> >> task releaseMajor(dependsOn: [increaseMajorVersion, clearDeliveryDir, >> deliverToExternal, saveVersion]) { >> description 'Release a new version of application, create tag and >> increase version' >> >> doLast { >> println "${appVersion} released" >> } >> } >> >> task releaseBeta(dependsOn: [increaseBetaVersion, clearDeliveryDir, >> deliverToExternal, saveVersion]) { >> description 'Release a new version of application, create tag and >> increase version' >> >> doLast { >> println "${appVersion} released" >> } >> } >> >> task releaseNightly(dependsOn: [increaseNightlyVersion, clearDeliveryDir, >> deliverToExternal, saveVersion]) { >> description 'Release a new version of application, create tag and >> increase version' >> >> doLast { >> println "${appVersion} released" >> } >> } >> >> //-------------------Utils---------------- >> >> class Version { >> def project >> def subprojects >> String versionName >> boolean release >> >> String toString() { return VersionUtils.toString(versionName) } >> >> Version increaseMajor() { versionName = VersionUtils.increaseMajor( >> versionName); apply(); this } >> >> Version increaseBeta() { versionName = VersionUtils.increaseBeta( >> versionName); apply(); this } >> >> Version increaseNightly() { versionName = VersionUtils. >> increaseNightly(versionName); apply(); this } >> >> void apply() { >> subprojects.findAll { project -> project.hasProperty('android') >> && project.android.hasProperty('applicationVariants') }.each { project -> >> project.android.defaultConfig.versionName = this.toString() >> project.android.defaultConfig.versionCode = VersionUtils. >> makeVersionCode(this.toString(), project.android.defaultConfig. >> minSdkVersion.mApiLevel as int) >> >> println "${product.name} versionName = >> ${project.android.defaultConfig.versionName}, versionCode = >> ${project.android.defaultConfig.versionCode}" >> >> } >> } >> >> void save() { >> project.ant.propertyfile(file: 'gradle.properties') { >> entry(key: "versionName", value: versionName) >> } >> project.ant.replaceregexp(file: 'gradle.properties', match: /^#[^ >> ].*\s*/, replace: "", flags: "g") >> } >> } >> >> >> >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "adt-dev" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to adt-dev+u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > Xavier Ducrohet > Android SDK Tech Lead > Google Inc. > http://developer.android.com | http://tools.android.com > > Please do not send me questions directly. Thanks! > -- You received this message because you are subscribed to the Google Groups "adt-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.