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 !