How do I upload an aar library to Nexus?

2020-06-21 06:08发布

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

6条回答
beautiful°
2楼-- · 2020-06-21 06:24

You can upload it with Maven or Gradle or manually.

For the manual upload you can just type the package value in the input to be 'aar' and upload as you desire.

查看更多
家丑人穷心不美
3楼-- · 2020-06-21 06:28

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.

查看更多
forever°为你锁心
4楼-- · 2020-06-21 06:30

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

Here's a good example for a more complex setup: http://zserge.com/blog/gradle-maven-publish.html

查看更多
神经病院院长
5楼-- · 2020-06-21 06:45

Use maven deploy plugin. Example command:

mvn deploy

This assumes you have correctly configured your pom.xml with distributonManagement section, telling all it needs to know about your Nexus repo

If you're that kind of people who dislike changing your pom.xml, or worse if your code doesn't even have pom.xml but you still want to upload to Nexus anyway, then you can still do it using

mvn deploy:deploy-file -Durl=http://mycompany/nexus/repo/blah -Dfile=/path/to/my/foo.aar -Dpackaging=aar -DgroupId=com.mycompany -DartifactId=foo -Dversion=1.2.3

Refer to maven deploy plugin doc for more info: https://maven.apache.org/plugins/maven-deploy-plugin/

查看更多
Rolldiameter
6楼-- · 2020-06-21 06:49

If you are building your project using Gradle, here there is a good tutorial to push your artifacts to Nexus:

https://medium.com/@scottyab/how-to-publish-your-open-source-library-to-maven-central-5178d9579c5#.acynm6j49

Basically, it adds a new Gradle task (uploadArchives) to push your artifacts. So doing something like:

>gradle clean build uploadArchives
查看更多
叼着烟拽天下
7楼-- · 2020-06-21 06:49

It doesn't make any sense that why nexus package have nothing for @aar file but if you try to upload it as a jar then it will not block you and everything is work as it is..

查看更多
登录 后发表回答