Upload multiple aar 's to Nexus using jenkins - gradle release

1.1k views Asked by At

I need to upload multiple aar's generated from a multi module project. My project structure as follows.

Project Root
  |--Main app
  |--Sub-Module1
  |--Sub-Module2
  |--Sub-Module3

Each sub module generates aar files that I need to upload the release version of all aars to Nexus However I do not want apks to be uploaded to Nexus.I am passing all the nexus url and cred from jenkins.

Here is my root build.gradle

release {
failOnCommitNeeded = false
failOnPublishNeeded = true
failOnSnapshotDependencies = true
failOnUnversionedFiles = false
failOnUpdateNeeded = true
revertOnFail = true
preCommitText = ''
preTagCommitMessage = '[Gradle Release Plugin] - pre tag commit: '
tagCommitMessage = '[Gradle Release Plugin] - creating tag: '
newVersionCommitMessage = '[Gradle Release Plugin] - new version commit: '
tagTemplate = '$version'
versionPropertyFile = './gradle.properties'
versionProperties = []
buildTasks = ['uploadAllArchives']
scmAdapters = [
        net.researchgate.release.GitAdapter
]
git {
    requireBranch = ''
  }
 }

 task ("uploadAllArchives") {
    doLast{
    println 'uploadAllArchives'
    subprojects.each { subProject->
        if(!subProject.name.contains('app') && !rootProject)
        it.uploadArchives.execute();
    }
  } 
}

publish-build.gradle

apply plugin: 'maven'

 uploadArchives {
       repositories {
        mavenDeployer {
            repository(url: (project.hasProperty('repoUrl') ? repoUrl 
               : sonatypeRepo)) {
                authentication(userName: sonatypeUsername, password: 
                 sonatypePassword)
                pom.groupId = sonatypeGroupID
                pom.artifactId = project.name
                pom.version = version

               }
           }
        }
     }

Sub-Modules build.gradle:

apply from: '../publish-build.gradle'

gradle clean build uploadArchives This successfully uploads my all snapshot aars to Nexus.

gradle release - It successfully do the release but not upload anything to Nexus However the build is successful.

Could you please help me what I am missing?

2

There are 2 answers

0
larsgrefer On

You can't use the normal maven plugin with android projects. You have to use this one: https://github.com/dcendents/android-maven-gradle-plugin

Also your uploadAllArchives task is redundant, just run gradle uploadArchives from the root project.

2
Hillkorn On

you can get that by adding

afterReleaseBuild.dependsOn project.getSubprojects().collect({it.getTasks().getByName("uploadArchives")})

That will do it if you want to upload it for all subProjects but if your root project also produces an artifact you have to replace getSubprojects() with getAllprojects()