Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 416
mattm Avatar asked Feb 13 '16 17:02

mattm


2 Answers

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.

like image 193
mattm Avatar answered Oct 21 '22 16:10

mattm


For Android, we normally have two build.gradle files the one at the top level folder, and another one in the specific module:

app/
---build.gradle
---module/
------build.gradle

In the app/build.gradle file of the clients of this library you will have to add:

repositories {
    jcenter()
    maven {
            url "http://localhost:8081/repository/test-maven-repo/"
        }
}

For you library app/module/build.gradle file:

apply plugin: 'maven'

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "http://localhost:8081/repository/test-maven-repo/") {
                authentication(userName: "admin", password: "admin123")
                pom.groupId = "com.example.test"
                pom.artifactId = "myexample.test"
                pom.version = '1.0.0'
            }
        }
    }
}

And you might want to run it just with:

./gradlew upload

Link to official documentation: Maven Publish Plugin.

like image 7
moxi Avatar answered Oct 21 '22 16:10

moxi