Gitlab 项目上传到Maven仓库
- Gitlab 项目上传到Maven仓库
- 1. 生成Deploy tokens
- 2.项目工程AS的build.gradle配置Maven
- 3. 拉取Maven库
Gitlab 项目上传到Maven仓库
1. 生成Deploy tokens
项目地址-》Settings-》Repository-》Deploy tokens-》Expand-》输入Name-》Create deploy token
记录生成后的密码,后面要用到
2.项目工程AS的build.gradle配置Maven
apply plugin: 'maven-publish'
afterEvaluate {
publishing {
repositories {
maven {
// 输入Url
url "https://git.test.cn/api/v4/projects/4313/packages/maven"
name "GitLab"
credentials(HttpHeaderCredentials) {
name = "Deploy-Token"
value = '输入生成access'
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
publications {
release(MavenPublication) {
from components.release
groupId "com.gitlab.test" // groupId
artifactId "lib-test" // artifactId
version "1.0.1" // 发布版本
}
}
}
}
上面的url地址是由你的gitlab地址
项目ID,可在Settings-》General-》Project ID看到
3. 拉取Maven库
settings.gradle添加Maven库
maven {
url "https://git.test.cn/api/v4/projects/4313/packages/maven"
name "GitLab"
credentials(HttpHeaderCredentials) {
name = "Deploy-Token"
value = '输入生成access'
}
authentication {
header(HttpHeaderAuthentication)
}
}
工程中的build.gradle添加依赖
implementation 'com.gitlab.test:lib-test:1.0.1'