uploadArchives empty archives when setting dependsOn

Hello everyone!
(I have posted the same question to here, no answers yet…)
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 the maven plugin to upload the generated .apk to a Maven repo (Nexus).

I have to add the archives to upload dynamically at execution time, because my build is using custom Android flavors and I don’t know at configuration time which artifacts will be created.
Everything works fine when I run uploadArchives normally:

def capitalizedVariantName = variant.name.capitalize()

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

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.

  • 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 artificats.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.

Does anyone has a solution for that?