I made a maven project saved into a gitlab project (PROJECT_A). With pipeline I publish this project into a gitlab maven repository. Here the settings.xml file
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Job-Token</name>
<value>${env.CI_JOB_TOKEN}</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
And this is the reference to the repository into the pom.xml
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/PROJECT_A_ID/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/PROJECT_A_ID/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/PROJECT_A_ID/packages/maven</url>
</snapshotRepository>
</distributionManagement>
The PROJECT_A jar is used as maven dependency into another project (PROJECT_B). Into the pom.xml of this latter project I had declared the repository reference where the jar is published, here the code
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/PROJECT_A_ID/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/PROJECT_A_ID/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/PROJECT_A_ID/packages/maven</url>
</snapshotRepository>
</distributionManagement>
If I run the project in local everything it's ok, the dependency is downloaded and I'm able to use it into PROJECT_B. But when I push some change into gitlab, when the pipeline run (into a gitlab shared runner) the command mvn clean install -DskipTests
I receive the error
[ERROR] Failed to execute goal on project cost-center: Could not resolve dependencies for project com.phatedeveloper:cost-center:jar:0.0.1: Could not find artifact com.phatedeveloper:pbm-dto-library:jar:1.0-SNAPSHOT in gitlab-maven (https://gitlab.com/api/v4/projects/20364942/packages/maven) -> [Help 1]