Setting pom version in mavenDeployer dynamically

I have an android project where I am trying to do a build, create a versionName and versionCode based on my git branch and git commit count and then upload an artifact to a nexus snapshot repository. For instance, I’d do a build and, using scripting, dynamically generate a versionName and versionCode and then combine these to form the name of my snapshot directory. For example, I’d upload a few files to 0.1.2-432-SNAPSHOT.

I’m using mavenDeployer in my app level build.gradle and have been having trouble pulling the versionCode and versionName in dynamically to set my pom version, artifactId, etc…

Here’s my code to generate the versionCode:

task getVersionCode(type: Exec) {
    commandLine './getVersionCode.sh'
    workingDir scriptDir
    standardOutput = new ByteArrayOutputStream()
    doLast {
        rootProject.ext.code = standardOutput.toString() as Integer
        println(rootProject.ext.code)
    }
}

Here’s my code to generate the versionName:

task getVersionName(type: Exec) {
    commandLine './getVersionName.sh'
    workingDir scriptDir
    standardOutput = new ByteArrayOutputStream()
    doLast {
        rootProject.ext.name = standardOutput.toString()
        println(rootProject.ext.name)
    }
}

Here’s my code for uploading:

uploadArchives {
    repositories {
        mavenDeployer {
            ext{
                theCode=1
                theName="myName"
            }
            snapshotRepository(url: "https://artifact.example.net/content/repositories/snapshots") {
                authentication(userName: artifactUsername, password: artifactPassword)
            }
            repository(url: "https://artifact.example.net/content/groups/public") {
                authentication(userName: artifactUsername, password: artifactPassword)
            }

            pom.version = "${rootProject.code.toString()}-${rootProject.name}-SNAPSHOT"
            pom.artifactId = appId
            pom.groupId = "com.example.mobile.android"
        }
    }
}

So what I do is call a task that runs a script that gets the number of git commits then saves that to the variable rootProject.ext.code and call a different task that runs a different script that generates the name and saves it to rootProject.ext.name. Those scripts work fine and I have verified that the variable gets set in each case. Now, the issue I run into is that when I run the uploadArchives task I reference the rootProject.ext.name and rootProject.ext.code but instead of getting the updated values that my scripts output I instead get the default values. This is very confusing and I don’t know how to proceed. Is there a way to dynamically set the pom.version, pom.artifactId and pom.groupID in the mavenDeployer?

I am struggling a very similar issue. Any updates so far? Did you manage to, solve it?