一.Gradle打包
在需要打包的module的build.gradle中添加如下代码:
group "项目groupId"//如:group "com.zcx.library"
version "版本号"//如:version "1.0.0"
uploadArchives {
repositories {
mavenDeployer {
repository(url: uri('输入目录名'))//如:repository(url: uri('../repo'))
}
}
}
同步之后在gradle中找到对应的module的uploadArchives执行,或者直接cmd cd到项目目录执行gradlew uploadArchives命令.
执行完后,在刚指定的目录生成项目的maven文件和jar包.
二.Gradle使用
1.Gradle插件依赖
如果是插件,在项目的根目录的build.gradle中的buildscript的repositories中添加maven {url uri(‘刚写maven的绝对目录’)},然后在dependencies 中添加插件,如下
buildscript {
repositories {
maven {url uri('本地maven仓库绝对地址')}//如:maven {url uri('D:\\maven\\repo')}
}
dependencies {
classpath '项目groupId:module名:版本号'//如:classpath 'com.zcx.library:library:1.0.0'
}
}
1.普通依赖
如果是普通依赖,在项目的根目录的build.gradle中的allprojects的repositories中添加maven {url uri(‘刚写maven的绝对目录’)},如下
allprojects {
repositories {
maven {url uri('本地maven仓库绝对地址')}//如:maven {url uri('D:\\maven\\repo')}
}
}
然后在你需要使用的module的build.gradle中将依赖添加到dependencies中,如下:
dependencies {
implementation '项目groupId:module名:版本号'//如:implementation 'com.zcx.library:library:1.0.0'
}