如何将aar库上传到Nexus?

mat*_*ttm 5 android nexus maven android-gradle-plugin aar

我有一个Android应用程序的Android aar库.它与直接包含在Android项目中的aar库一起正常工作.我想将此库移动到我的内部Nexus maven存储库,以便其他开发人员也可以使用该库.

如何将aar上传到Nexus(Maven存储库)?在Web界面中没有明显的选项:

Nexus网络界面

mox*_*oxi 7

对于 Android,我们通常有两个 build.gradle 文件,一个在顶级文件夹中,另一个在特定模块中:

app/
---build.gradle
---module/
------build.gradle
Run Code Online (Sandbox Code Playgroud)

在该库客户端的app/build.gradle文件中,您必须添加:

repositories {
    jcenter()
    maven {
            url "http://localhost:8081/repository/test-maven-repo/"
        }
}
Run Code Online (Sandbox Code Playgroud)

对于你的库app/module/build.gradle文件:

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'
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

您可能只想使用以下命令运行它:

./gradlew upload

官方文档链接: Maven Publish Plugin


mat*_*ttm 5

我使用gradle的maven插件通过修改Android build.gradle文件上传到Nexus.

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'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

要上传:gradlew upload,请使用gradlewAndroid Studio项目提供的脚本.

您还可以将身份验证参数移动到不受版本控制的文件中.