英文:
Dependency hosted in GitLab's maven repository is not found during pipelines job
问题
我遇到了一个非常奇怪的问题。当我在我的计算机上构建插件时,一切都正常。但是当插件在GitLab的流水线中构建时,构建失败,提示找不到依赖项。
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find any matches for fr.group:theplugin:5.0.+ as no versions of fr.group:theplugin are available.
Searched in the following locations:
- https://gitlab.com/api/v4/groups/GROUP-ID/-/packages/maven/fr/group/theplugin/maven-metadata.xml
我正在使用GitLab的Maven存储库(Package registry)来托管我的Minecraft插件的构件。找不到的依赖项托管在包注册表中。我尝试删除了我的Gradle缓存并在我的计算机上重新构建。依赖项如预期下载。所以这让我说构件在包注册表中是可用的。
我的安装的Gradle版本与包装程序版本相同(Gradle 6.5.1)。我也尝试在我的计算机上运行包装程序,以防万一,它也运行正常。
这是我的 build.gradle
文件:
// 构建插件
plugins {
id 'maven-publish'
id 'java'
}
// 上游Maven仓库
repositories {
mavenCentral()
maven {// Gitlab的组的依赖项
url "https://gitlab.com/api/v4/groups/GROUP-ID/-/packages/maven"
name "GitLab"
credentials(HttpHeaderCredentials) {
name = 'Private-Token'
value = gitLabPrivateToken
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
group = 'fr.mygroup'
version = 1.0.0
dependencies {
compileOnly group: 'fr.group', name: 'theplugin', version: '5.0.+', transitive: false
}
compileJava {
sourceCompatibility = '1.8'
options.encoding = 'UTF-8'
}
// Maven发布
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
maven {
url "https://gitlab.com/api/v4/projects/PROJECT-ID/packages/maven"
credentials(HttpHeaderCredentials) {
name = "Private-Token"
value = gitLabPrivateToken
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
当然,我在真正的 build.gradle
文件中替换了 GROUP-ID
和 PROJECT-ID
。
这是我的 .gitlab-ci.yml 文件:
image: java:8
before_script:
- chmod +x gradlew
stages:
- build
- test
- publish
# 构建阶段
build:
only:
- tags
tags:
- docker
stage: build
script:
- ./gradlew -g /cache/.gradle clean assemble -PgitLabPrivateToken=$CI_CUSTOM_TOKEN
allow_failure: false
# 使用生成的构建输出来运行测试。
test:
only:
- tags
tags:
- docker
stage: test
script:
- ./gradlew -g /cache/.gradle check -PgitLabPrivateToken=$CI_CUSTOM_TOKEN
# 将构件发布到GitLab
publish:
only:
- tags
tags:
- docker
stage: publish
script:
- ./gradlew -g /cache/.gradle clean publish -PgitLabPrivateToken=$CI_CUSTOM_TOKEN
CI_CUSTOM_TOKEN
环境变量包含一个带有GitLab帐户中至少是维护者(也许是所有者,我不记得了)的 api 权限的 个人访问令牌。
我尝试创建了一个新的GitLab组,将我尝试构建的插件克隆到其中,我创建了相同的 CI_CUSTOM_TOKEN
环境变量,然后运行了一个流水线,它完美地工作了。
如果有不清楚的地方或需要更多信息,请告诉我。
感谢您阅读并希望能提供帮助(我希望如此)。
祝你有美好的一天!
英文:
I'm encountering a very weird issue. When I build my plugin on my computer everything works fine. But when the plugin is build in the GitLab's pipeline, the build fails saying there's a dependency not found.
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find any matches for fr.group:theplugin:5.0.+ as no versions of fr.group:theplugin are available.
Searched in the following locations:
- https://gitlab.com/api/v4/groups/GROUP-ID/-/packages/maven/fr/group/theplugin/maven-metadata.xml
I'm using GitLab's maven repository (Package registry) to host artefacts of my own minecraft plugins. The dependency not found is hosted in the package registry. I've tried to remove all my gradle cache and build again on my computer. The dependency was downloaded as expected. So this makes me say that the artefact is available in the package registry.
My installed gradle version is the same as the wrapper (gradle 6.5.1). I've also tried to run the wrapper on my computer just in case and it works fine too.
Here's my build.gradle
:
// Build plugins
plugins {
id 'maven-publish'
id 'java'
}
// Upstream Maven repositories
repositories {
mavenCentral()
maven {//Dependencies on the Gitlab's group
url "https://gitlab.com/api/v4/groups/GROUP-ID/-/packages/maven"
name "GitLab"
credentials(HttpHeaderCredentials) {
name = 'Private-Token'
value = gitLabPrivateToken
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
group = 'fr.mygroup'
version = 1.0.0
dependencies {
compileOnly group: 'fr.group', name:'theplugin', version: '5.0.+', transitive: false
}
compileJava {
sourceCompatibility = '1.8'
options.encoding = 'UTF-8'
}
// Maven publish
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
maven {
url "https://gitlab.com/api/v4/projects/PROJECT-ID/packages/maven"
credentials(HttpHeaderCredentials) {
name = "Private-Token"
value = gitLabPrivateToken
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
Of course I've replaced GROUP-ID
and PROJECT-ID
in my real build.gradle
.
And here is my .gitlab-ci.yml:
image: java:8
before_script:
- chmod +x gradlew
stages:
- build
- test
- publish
# Build stage
build:
only:
- tags
tags:
- docker
stage: build
script:
- ./gradlew -g /cache/.gradle clean assemble -PgitLabPrivateToken=$CI_CUSTOM_TOKEN
allow_failure: false
# Use the generated build output to run the tests.
test:
only:
- tags
tags:
- docker
stage: test
script:
- ./gradlew -g /cache/.gradle check -PgitLabPrivateToken=$CI_CUSTOM_TOKEN
# Publish the artifact to GitLab
publish:
only:
- tags
tags:
- docker
stage: publish
script:
- ./gradlew -g /cache/.gradle clean publish -PgitLabPrivateToken=$CI_CUSTOM_TOKEN
The CI_CUSTOM_TOKEN
environment variable contains a personal access token with the scope api of a GitLab's account that is at least maintainer (maybe owner I don't remember) in the GitLab's group in question.
I've tried to create a new GitLab group in witch I've cloned the plugin I'm trying to build, I've created the same CI_CUSTOM_TOKEN
environement variable, then I runned a pipeline and it perfectly worked.
Please let me know if something is not clear or if you need more information.
Thank you for reading and maybe helping (I hope)
Have a nice day !
答案1
得分: 4
问题是CI_CUSTOM_TOKEN
环境变量中选中了保护变量选项。因此,该变量未传递给由未受保护标签触发的流水线。奇怪的是,我本应该遇到权限错误或类似的问题,但它只是说找不到依赖项。
不管怎样,我取消了该选项,现在它完美运行。
英文:
The problem was that the option Protect variable was checked in the CI_CUSTOM_TOKEN
environement variable. In consequencies the variable was not passed to pipelines triggered by not protected tags. What's weird is that I should have had a permissions error or something but it just said the dependency was no found.
Anyway, I unchecked the option and now it's perfectly working.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论