Search code examples
androidmavenandroid-gradle-pluginnexusaar

How do I upload an aar library to Nexus?


I have an Android aar library I am using with an Android application. It is working correctly with the aar library included directly in the Android project. I would like to move this library to my internal Nexus maven repository, so that other developers can use the library too.

How do I upload the aar to Nexus (the Maven repository)? There is no apparent option to do so in the web interface:

Nexus web interface


Solution

  • I used gradle's maven plugin to upload to Nexus by modifying the Android build.gradle file.

    apply plugin: 'maven'
    
    dependencies {
        deployerJars "org.apache.maven.wagon:wagon-http:2.2"
    }
    
    uploadArchives {
        repositories.mavenDeployer {
            configuration = configurations.deployerJars
            repository(url: "https://my.example.com/content/repositories/com.example/") {
                authentication(userName: "exampleUser", password: "examplePassword")
                pom.groupId = "com.example"
                pom.artifactId = "myexample"
                pom.version = '1.0.0'
            }
        }
    }
    

    To upload: gradlew upload, using the gradlew script that is provided by the Android Studio project.

    You can also move the authentication parameters into a file that is not version controlled.