如何将moudle上传到阿里云仓库,通过gradle依赖的方式添加到项目中

246 阅读1分钟

1、新建moudle并编写相关moudle代码。

2、注册登录到阿里云仓库管理地址。链接: packages.aliyun.com/maven 选择release生仓库

3、选择以gradle方式引入仓库,点击copy个人仓库设置代码。

image.png 说明: 在maven文件中需要配置库名称、版本号以及artifactId这三个参数。举例如下:

// 上传到阿里云
apply plugin: 'maven'
uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: 'https://packages.aliyun.com/maven/repository/2125252-release-BrxKdf/') {
                authentication(
                        userName: 'xxxxxxx',
                        password: 'xxxxxxx'
                )
            }
            snapshotRepository(url: 'https://packages.aliyun.com/maven/repository/2125252-snapshot-ApGhfk/') {
                authentication(
                        userName: 'xxxxxxx',
                        password: 'xxxxxxx'
                )
            }
            pom.version = '1.0.0'
            pom.artifactId = 'widgetlib'
            pom.groupId = 'com.xianpeng.widgetlib'
        }
    }

4、在moudle中依次执行clean、build、upload命令,表示编译后上传到对应的阿里云maven库中,命令分别执行成功之后,阿里云仓库中包列表会显示出上传的moudle。

image.png

至此,上传步骤完成。

5、在主工程如何引入此moudle?

5.1 在主工程的build.gradle中,allprojects节点下,添加moudle的仓库信息,以便访问到此仓库。

image.png

5.2 在dependencies列表中引入 对应的仓库名和版本号,点击同步即可。

image.png

至此,引入moudle到主工程步骤完成。