最近发现gitlab提供了maven的功能,研究了下怎么用,下面是摸索之后得出的方法
如何设置
- 参考这个文档:https://docs.gitlab.com/ee/user/packages/maven_repository/index.html
- 生成发布和读取的token
Settings -> Repository -> Deploy Tokens -> 分别生成read/wirte token
如何发布
- 相关参数设置
libxxx/build.gradle
android {
}
apply from: rootProject.file('git-publish.gradle')
git-publish.gradle
apply plugin: 'maven-publish'
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
groupId = "org.yeshen"
artifactId = "tools"
version = "1.0.0"
}
}
repositories {
maven {
url "https://gitlab.yeshen.org/api/v4/projects/100/packages/maven"
credentials {
username "${这是步骤一生成的Deploy Tokens Name}"
password "${这是步骤一生成的token}"
}
}
}
}
}
- 发布
./gradlew :tools:publish
如何使用
repositories {
maven {
url "https://gitlab.yeshen.org/api/v4/projects/100/packages/maven"
credentials(HttpHeaderCredentials) {
name = 'Deploy-Token'
password "${这是步骤一生成的密码}"
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
dependencies {
implementation 'org.yeshen:tools:1.0.0'
}
注意点
- 我看到也有些人发布和使用都可以用一样的maven配置,但是我自己试了一轮,是不能用 authentication {header(HttpHeaderAuthentication}
- 使用的时候,有个credentials,其中的name必须是
Deploy-Token
,不然会拉不到仓库。
相关文章:
20250103 更新
适配AGP7.1+ : https://blog.csdn.net/yeshennet/article/details/144916069