GitLab Package Registry failed to Resolve Maven Dependencies

Problem to solve

After upgrading our GitLab instance from version 14.4.0 to 17.0, we have been unable to resolve Maven dependencies from our GitLab package registry. This functionality worked correctly in version 14.4.0. Below are the details of our setup and the issues we are encountering.

Details

  • GitLab Version: 17.0
    Issue: Unable to resolve Maven dependencies from the GitLab package registry.
    Previous Working Version: 14.4.0

In my others projects that I need use the libraries of my main project that I use as repository. I include in pom.xml configurations for access this libraries

<repositories>
    <repository>
        <id>gitlab-maven</id>
        <url>{SCM-HOME}/api/v4/projects/595/packages/maven</url>
    </repository>
</repositories>

<distributionManagement>
    <repository>
        <id>gitlab-maven</id>
        <url>{SCM-HOME}/api/v4/projects/595/packages/maven</url>
    </repository>
    <snapshotRepository>
        <id>gitlab-maven</id>
        <url>{SCM-HOME}/api/v4/projects/595/packages/maven</url>
    </snapshotRepository>
</distributionManagement>

In my .m2 repository. I created settings.xml with this structure

<settings>
  <servers>
    <server>
      <id>gitlab-maven</id>
      <username>your_gitlab_username</username>
      <password>your_project_access_token</password>
    </server>
  </servers>
</settings>

I tried use this other format:

<settings>
  <servers>
    <server>
      <id>central-proxy</id>
      <configuration>
        <httpHeaders>
          <property>
            <name>Private-Token</name>
            <value>my-token</value>
          </property>
        </httpHeaders>
      </configuration>
    </server>
  </servers>
  </settings>

Information about token

I try use two differents types of token: Personal and project Token

For personal I create token with this specifications:

  • Scopes:
    • api
    • read_api
    • read_registry
    • write_registry

For project token I create token with this specifications:

  • Scopes:
    • api
    • read_api
    • read_registry
    • write_registry
  • Role:
    • Guest

When I try install dependencies, after run mvn clean install -U, I receive this error

Could not resolve dependencies for project br.com.xpto:project:war:${PROJECT_VERSION-SNAPSHOT}: Could not find artifact br.com:xpto:jar:1.0-FINAL in gitlab-maven ({SCM-HOME}/api/v4/projects/595/packages/maven) -> [Help 1]

I tried troubleshooting via curl for check if my library is available. I run this command:

curl --header "PRIVATE-TOKEN: your_project_access_token" {SCM-HOME}/api/v4/projects/595/packages/maven/br/com/xpto/1.0-FINAL/xpto-1.0-FINAL.jar
{"message":"404 Package Not Found"}

Although when I access my project in this url {SCM-HOME}/api/v4/projects/595/packages I receive this output:

{
id: 15,
name: "br/com/xpto",
version: "1.0-FINAL",
package_type: "maven",
status: "default",
_links: {
web_path: "/corporate/java-repository/-/packages/15",
delete_api_path: "{SCM-HOME}/api/v4/projects/595/packages/15"
},
created_at: "2024-07-22T16:12:22.690-03:00",
last_downloaded_at: "2024-07-23T11:58:13.538-03:00",
tags: [ ]
}
]

The resource is available for download and create my artifacts.

Steps to reproduce

  • Create one gitlab-project for use as Package Registry
  • upload one library or package for this repository
  • Create or use other Java Project
  • Save in pom.xml for this project the configuration for use this package repository
  • Create one personal token
  • Try install or compile package of your project.

Configuration

For this case. I should you use this topics of GitLab Docs:

Versions

Please select whether options apply, and add the version information.

  • [ X ] Self-managed
  • GitLab.com SaaS
  • Self-hosted Runners

Versions

  • GitLab v17.0.1-ee
  • GitLab Runner v 17.0.0

I would appreciate any insights or guidance on resolving this issue. Specifically, I am looking for:

Confirmation of any changes in GitLab 17.0 that could affect Maven repository access.
Troubleshooting steps to identify and resolve the 401 Unauthorized and 404 Not Found errors.
Best practices for configuring Maven to work with GitLab 17.0’s package registry.
Thank you for your assistance.

1 Like