Nexus搭建maven私服-Android上传aar和依赖(3)

前言:公司有几个项目都要依赖同一个底层模块X,而这些项目都在不同大牛手上维护着,而又不可能直接上传到公共的仓库,于是就在自己的服务器上弄一个仓库。
PS,基于VMWare上的CenterOS6,搭建的Nexus私服。

0. Thanks

AndroidStudio 使用gradle 脚本上传aar文件到Nexus Maven 私有服务器

1. Nexus创建自己的仓库

访问:http://192.168.239.10:8081/nexus,当然你的IP不一定是这个。

先创建一个你要上传的仓库信息:

  • 点击add 选择Hosted Repository 输入Repository ID 如com.tibby.hello

  • Repository Name 输入helloworld,

  • Deploymnet Policy 选择Allow Redeploy

  • 然后点击save之后,自己的第三方库就在自己的Nexus 服务上创建好了,仓库地址为:http://192.168.239.10:8081/nexus/content/repositories/com.tibby.hello/

1.png

2. Android Studio 配置

  • 新建一个module,这个module就是你要编译的aar

  • module下gradle配置如下,添加一个TASK

...
apply plugin: 'maven'
...
uploadArchives {
    repositories.mavenDeployer {
        // 修改为自己刚才创建的仓库地址
        repository(url: "http://192.168.239.10:8081/nexus/content/repositories/com.tibby.hello/") {
            authentication(userName: "admin", password: "1421")
        }
        pom.version = "1.0.2"
        pom.artifactId = "helloworld"
        pom.groupId = "com.tibby.hello"
        pom.name = "hello"
        pom.packaging = 'aar'
    }
}

groupId,version要注意填好。

  • 然后,在Gradle projects列表中可以看到upload的Task
3.png

点击后即可编译上传,success后就可以了。

  • 然后在Nexus后台可以看到:
2.png

3. Android Studio 中引用

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    //添加仓库
    repositories {
        maven {
            url "http://192.168.239.10:8081/nexus/content/repositories/com.tibby.hello/"
        }
    }
    compile 'com.tibby.hello:helloworld:1.0.1@aar'
}

你可能感兴趣的:(Nexus搭建maven私服-Android上传aar和依赖(3))