目前没有看到简单介绍gitlab当maven存储库的资料。于是整理了一篇,方便有需要的朋友少走弯路。
1.在gitlab创建一个新的安卓项目,在项目中选择“设置”-“仓库”-“部署令牌”-填入相关信息-创建部署令牌
填完之后会生成 ,token令牌**(要记下来,关闭之后就无法再查看token)**
2.发布配置:
publishing {
publications {
if (isDebugLib) {
// 测试环境
debug(MavenPublication) {
//应用发布版本变体的组件
from components.debug
pom {
name = mavenName
description = mavenDescription
//版本号 即: implementation 'com.google.android.material:material:1.4.0' 的1.4.0
version = mavenVersionDebug
//即: implementation 'com.google.android.material:material:1.4.0' 的 material
artifactId = mavenArtifactId
//即: implementation 'com.google.android.material:material:1.4.0' 的 com.google.android.material
groupId = mavenGroupId
}
}
} else {
// 正式环境
release(MavenPublication) {
from components.release
pom {
name = mavenName
description = mavenDescription
version = mavenVersionRelease
artifactId = mavenArtifactId
groupId = mavenGroupId
}
}
}
}
repositories {
maven {
//<这是要替换成自己的> 仓库地址和你们自己gitlab的浏览器地址栏那边的一样,项目id在项目名字的下方,token令牌就是刚刚需要记下来的令牌
url = "https://gitlab.<仓库的地址>.com/api/v4/projects/<项目id>/packages/maven/"
credentials(org.gradle.api.credentials.HttpHeaderCredentials) {
name = "Deploy-Token"
value = '<token令牌>'
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
3.依赖配置:
repositories {
maven {
//仓库群组名就是gitlab项目目录的上一级
url "https://gitlab.<仓库的地址>.com/api/v4/groups/<仓库的群组名>/-/packages/maven"
name "GitLab"
credentials(HttpHeaderCredentials) {
name = 'Deploy-Token'
value = '<token令牌>'
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
至此所有配置完毕,点击gradle的publish命令即可上传远端仓库
参考资料:https://docs.gitlab.com/ee/user/packages/maven_repository/index.html#publish-by-using-gradle