I have a Android app building with Gradle. I am using the gradle-release plugin to create automatic releases, and then the uploadArchives task from Gradle to upload the generated .apk to a Maven repo (Nexus).
I have to add the archives to upload dynamically at runtime, because my build is using custom Android flavors. Everything works fine when I run the uploadArchives from the command line:
variant.outputs.each { output ->
def apkFile = output.outputFile
tasks."assemble${capitalizedVariantName}" << {
artifacts.archives [file: apkFile, classifier: variant.baseName]
}
}
uploadArchives {
repositories {
mavenDeployer {
pom.groupId = PROJECT_GROUP
pom.artifactId = PROJECT_NAME
}
}
}
Then I run:
./gradlew assembleFlavorNameRelease uploadArchives
And the .apk is correctly uploaded to Nexus.
I have the need to run the uploadArchives task BEFORE the release plugin automatically changes the version name of the project and commit. Basically:
- current version: 0.1.0-SNAPSHOT
- run release
- version becomes: 0.1.0
- build (build task)
- upload this build to Nexus (uploadArchives task)
- update the version to: 0.1.1-SNAPSHOT (updateVersion task)
To achieve this, what I have done is to have the updateVersion task of the gradle-release plugin depending on the uploadArchives
updateVersion.dependsOn uploadArchives
Well, when I do this, the artifacts.archives. is empty, so no upload.
I suspect that, maybe, since I add the uploadArchives task as dependency of a task of the release plugin, then the "namespace" is different, so basically the uploadArchives task does not use the "same instance" of artifacts.archives, filled during the build.