Konubinix' opinionated web of thoughts

Maven Packages in the Gitlab Package Repository

Fleeting

Maven packages in the Package Repository | GitLab

Put the following in some settings.xml file

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

Then the following in some pom.xml file.

<repositories>
  <repository>
    <id>gitlab-maven</id>
    <url>https://gitlab.example.com/api/v4/projects/PROJECT_ID/packages/maven</url>
  </repository>
</repositories>
<distributionManagement>
  <repository>
    <id>gitlab-maven</id>
    <url>https://gitlab.example.com/api/v4/projects/PROJECT_ID/packages/maven</url>
  </repository>
  <snapshotRepository>
    <id>gitlab-maven</id>
    <url>https://gitlab.example.com/api/v4/projects/PROJECT_ID/packages/maven</url>
  </snapshotRepository>
</distributionManagement>

The doc says to run the following.

mvn dependency:get -Dartifact=com.nickkipling.app:nick-test-app:1.1-SNAPSHOT

But the following should be run instead.

mvn -s settings.xml -f dir_with_the_pom/ dependency:get -Dartifact=com.nickkipling.app:nick-test-app:1.1-SNAPSHOT

Beware of using colon (:) to separate the group id and the artifact id and possibly use -U in case of try and errors or else it will cache the error.

Note also that it works only for artifacts, not for maven parent packages.