Gitlab packages 仓库使用

510 阅读1分钟

创建 Deploy token

在项目首页,打开【设置】 - 【仓库】页面,展开【Deploy tokens】,创建一个部署令牌。

点击【创建部署令牌】,系统生成一个 token,记录下来,页面关闭后就不可见了。

gradle 推送配置

项目 ID

在项目首页获取项目 ID

企业微信截图_204e0f3e-9149-49ce-b5f3-5967b87bc56e.png

Maven url 规则

git.example.com/api/v4/proj…<PROJECT_ID>/packages/maven

apply plugin: 'maven-publish'
afterEvaluate {
publishing {
repositories {
maven {
url "https://git.example.com/api/v4/projects/4019/packages/maven"
                name "GitLab"
                credentials(HttpHeaderCredentials) {
name = "Deploy-Token"
                    value = 'XXuipC-yk2SC4NtxTy5b' // 填入上面获取的部署token
                }
authentication {
header(HttpHeaderAuthentication)
                }
}
}

publications {
release(MavenPublication) {
from components.release
                groupId "com.example.tool"
                artifactId "lib-tool"
                version "1.0.0"
            }
}
}
} 

拉取

// 验证 gitlab maven 仓库
maven {
url "https://git.example.com/api/v4/projects/4019/packages/maven"
    name "GitLab"
    credentials(HttpHeaderCredentials) {
name = "Deploy-Token"
        value = 'XXuipC-yk2SC4NtxTy5b'
    }
authentication {
header(HttpHeaderAuthentication)
    }
} 
implementation 'com.example.tool:lib-tool:1.0.0'