Pull a Maven Package from a Package Repository
Overview
The product team will be responsible for adding the package as a dependency to their project, setting up the link to the package repository in the pom.xml file, and creating the ci_settings.xml file that will contain the job token used to pull the package from the repository.
Steps
Update the pom.xml File
Add the package as a dependency for the project. An example XML is provided below. The product team will update the values for groupId, artifactId, and version as appropriate.
xml<dependency> <groupId>maven-spring.example</groupId> <artifactId>your-package</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency>Add a reference to the package repository. An example XML is provided below. The product team will update the value for ID as appropriate.
In this example, the variable
CI_SERVER_URLwill be the URL of the GitLab server, andMAVEN_PACKAGE_PROJECT_IDwill be the GitLab project number of the package repository you are pulling the package from.xml<repositories> <repository> <id>maven-world-package</id> <url>${env.CI_SERVER_URL}/api/v4/projects/${env.MAVEN_PACKAGE_PROJECT_ID}/packages/maven</url> </repository> </repositories> <distributionManagement> <repository> <id>maven-world-package</id> <url>${env.CI_SERVER_URL}/api/v4/projects/${env.MAVEN_PACKAGE_PROJECT_ID}/packages/maven</url> </repository> <snapshotRepository> <id>maven-world-package</id> <url>${env.CI_SERVER_URL}/api/v4/projects/${env.MAVEN_PACKAGE_PROJECT_ID}/packages/maven</url> </snapshotRepository> </distributionManagement>
Add a ci_settings.xml File.
A sample is provided below. Note that the ID in the ci_settings.xml file must match the ID in the repositories section of the pom.xml file. In this example, CI_JOB_TOKEN contains a job token used to authenticate to the package repository.
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>maven-world-package</id>
<configuration>
<httpHeaders>
<property>
<name>Job-Token</name>
<value>${env.CI_JOB_TOKEN}</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>Shared Artifacts Between Projects
The CI_JOB_TOKEN(s) for each client repo should be granted access in the package repo's Settings→CI/CD→Token Access.
To pull a shared package from another repository, the above changes should be made to the pom.xml and ci_settings.xml files of the project that is downloading the shared artifact, and the ${env.MAVEN_PACKAGE_PROJECT_ID} should be changed to the source artifact's project ID.
In order for ci_settings to be included in your build, be sure to open a ticket with the MDO team so that they can add the following to the project variables to ensure ci_settings.xml gets included.
MAVEN_BUILD_OPTS: "-DskipTests -s ci_settings.xml"