1.简介
日常开发过程中, 我们可能会封装一些公共的组件, 减少相同代码重复编写的问题,
当组件写好后,我们需要把组件发布到Maven仓库, 供其他同事使用.
2.Gradle 多模块项目
此处重点不在于介绍多模块项目的创建, 因此不缀诉.
2.1 gradle.properties配置
2.2 build.gradle中配置子模块的打包规则
subprojects {
repositories {
mavenLocal()
maven {
url "http://maven.aliyun.com/nexus/content/groups/public/"
}
// 添加自定义仓库
}
// 推送镜像到阿里云仓库.
apply plugin: "maven"
uploadArchives {
repositories {
mavenDeployer {
repository(url: 'https://packages.aliyun.com/maven/repository/2058632-release-CGgriO/') {
authentication(
userName: '${userName}',
password: '${password}'
)
}
snapshotRepository(url: 'https://packages.aliyun.com/maven/repository/2058632-snapshot-8Z2Prh/') {
authentication(
userName: '${userName}',
password: '${password}' )
}
// 当前项目下的所有模块都推送到ali云仓库.
pom.whenConfigured { pom ->
pom.dependencies.forEach { dep ->
if (dep.getVersion() == "unspecified") {
dep.setGroupId("${bobProjectGroupId}")
dep.setVersion("${bobProjectVersion}")
}
}
}
}
}
}
}
其中,authentication中配置公司阿里云仓库的userName和password, version字段如果是以-SNAPSHOT结尾,则会推送到快照仓库, 如果以-RELEASE结尾, 则会推送到正式(稳定)仓库。
2.3 通过gralde task uploadArchives, 即可完成代码推送,或则通过Gradle工具进行推送