【问题标题】:How do I upload an aar library to Nexus?如何将 aar 库上传到 Nexus?
【发布时间】:2016-05-24 19:42:27
【问题描述】:

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

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

【问题讨论】:

    标签: android maven android-gradle-plugin nexus aar


    【解决方案1】:

    使用 Maven 部署插件。示例命令:

    mvn deploy
    

    这假设你已经正确配置了你的 pom.xml 和 distributonManagement 部分,告诉它需要知道的关于你的 Nexus repo 的所有信息

    如果您是那种不喜欢更改 pom.xml 的人,或者更糟糕的是,如果您的代码甚至没有 pom.xml 但您仍然想上传到 Nexus,那么您仍然可以使用

    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
    

    有关更多信息,请参阅 maven 部署插件文档:https://maven.apache.org/plugins/maven-deploy-plugin/

    【讨论】:

    • 该命令给我以下错误:您指定的目标需要执行一个项目,但此目录 (PATH_TO_AAR_PARENT_FOLDER) 中没有 POM。请确认您从正确的目录调用了 Maven。
    【解决方案2】:

    您可以使用 Maven 或 Gradle 或手动上传。

    对于手动上传,您只需在输入中键入包值“aar”并根据需要上传。

    【讨论】:

      【解决方案3】:

      如果您使用 Gradle 构建项目,这里有一个很好的教程可以将您的工件推送到 Nexus:

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

      基本上,它会添加一个新的 Gradle 任务(uploadArchives)来推送您的工件。所以做类似的事情:

      >gradle clean build uploadArchives
      

      【讨论】:

        【解决方案4】:

        我使用gradle's maven plugin 通过修改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'
                }
            }
        }
        

        上传:gradlew upload,使用 Android Studio 项目提供的 gradlew 脚本。

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

        【讨论】:

          【解决方案5】:

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

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

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

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

          为你的库 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'
                      }
                  }
              }
          }
          

          你可能想运行它:

          ./gradlew upload

          官方文档链接: Maven Publish Plugin.

          【讨论】:

          【解决方案6】:

          为什么nexus包没有任何@aar文件没有任何意义但是如果你尝试将它作为一个jar上传那么它不会阻止你并且一切都可以正常工作..

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2020-06-22
            • 1970-01-01
            • 2016-07-18
            • 2017-03-03
            • 2019-10-28
            • 2016-11-30
            • 1970-01-01
            • 2021-01-09
            相关资源
            最近更新 更多