'Artifact cannot be resolved from gitlab repository - only in pom.xml, while GET works?

I created a commons artifact in a gitlab repository.

I can already download the artifact from within a webbrowser:

https://git.my-company.com/api/v4/projects/295/packages/maven/com/example/hello-commons/1.0.0/hello-commons-1.0.0.jar

But when I try letting maven fetch the dependency, I get the following error:

[WARNING] The POM for com.example:hello-commons:jar:1.0.0 is missing, no dependency information available Downloading from gitlab-maven: https://git.my-company.com/api/v4/projects/295/packages/maven/com/example/hello-commons/1.0.0/hello-commons-1.0.0.jar

This is my pom.xml, what might be missing?

<repositories>
    <repository>
        <id>gitlab-maven</id>
        <url>https://git.my-company.com/api/v4/projects/295/packages/maven</url>
    </repository>
</repositories>
<distributionManagement>
    <repository>
        <id>gitlab-maven</id>
        <url>https://git.my-company.com/api/v4/projects/295/packages/maven</url>
    </repository>
</distributionManagement>


Solution 1:[1]

I didn't know that a private token has to be set into ~/.m2/settings.xml as follows:

<settings>
  <servers>
    <server>
      <id>gitlab-maven</id>
      <configuration>
        <httpHeaders>
          <property>
            <name>Private-Token</name>
            <value>PRIVATE_TOKEN_UUID</value>
          </property>
        </httpHeaders>
      </configuration>
    </server>
  </servers>
</settings>

The token must be of scope read_api.

Solution 2:[2]

Check in your local m2 repository (C:\Users\YourUserName.m2\repository) If the folder com/example/hello-commons has been created. If the folder created but download failed it won't retry for a while. Try to delete that folder and run your maven build again

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 membersound
Solution 2 Michael Gantman