1.找到要上传Module的build.gradle并将如下代码加入到该文件中
apply plugin: 'maven'
uploadArchives {
repositories.mavenDeployer {
def mavenDirPath = file('F:\\mavendir') // 本地存放目录(自行选择),可放在gradle.properties文件中引用
repository(url: "file://${mavenDirPath.absolutePath}") // 必须双引号,单引号不会转义$
pom.project {
groupId "com.liuy.maven.baselibrary" // 可以随意取,一般取包名
artifactId "baselibrary" // 可以随意取,一般取库的名字
version "0.0.0.0" // 版本号
}
}
}
2.点击Terminal进入命令模式,输入如下命令
gradlew :baselibrary:uploadArchives
其中baselibrary是刚才编写文件中的artifactid
![](https://img.haomeiwen.com/i16249515/ec7f4a12076657b2.png)
3.接下里等待编译完成
完成后,会在F盘生成mavendir的文件夹
在文件的目录中也可以看到下面这些文件
![](https://img.haomeiwen.com/i16249515/d8ecefe1c8cc7127.png)
![](https://img.haomeiwen.com/i16249515/8f4ee4792f017d64.png)
4.创建自己的repository
在github上创建自己的repository
![](https://img.haomeiwen.com/i16249515/48eab7a1a021f172.png)
会生成如下信息
![](https://img.haomeiwen.com/i16249515/a2265a0d04c609a3.png)
5.根据提示上传文件到github上
![](https://img.haomeiwen.com/i16249515/803ee80046bd9a1e.png)
上传完成后如图所示
6.为倒入做准备修改url
例如我现在的地址是
https://github.com/freedomangelly/BaseLibrary
将 github.com ——> raw.githubusercontent.com
即https://raw.githubusercontent.com/freedomangelly/BaseLibrary
再在末尾追加/master
表示当前要选用的是master分支的内容
即https://raw.githubusercontent.com/freedomangelly/BaseLibrary/master
com.liuy.maven.baselibrary:baselibrary:0.0.0.0
7.使用新建的仓库
在项目的Build.gradle中添加上面拼写的https://raw.githubusercontent.com/freedomangelly/BaseLibrary/master
![](https://img.haomeiwen.com/i16249515/98493ff1d6be1253.png)
在module中添加
implementation 'com.liuy.maven.baselibrary:baselibrary:0.0.0.0'
就是你在编译module的时候填写的那些东西
![](https://img.haomeiwen.com/i16249515/8f11e0f0fb56f296.png)
即:groupId:artifactId:version
之后就可以在项目中使用了库了
PS:我倒入库的时候不知道为什么总是不成功,反复的重试,重试了5分钟吧,才成功,不知道什么原因
网友评论