Pull a Maven Package from a Package Repository
The Product Team will be responsible for the 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.
A. Updates to the pom.xml file:
- Add the package as a dependency for the project. Sample xml is provided below. The Product Team will update the values for groupId, artifactId, and version as appropriate.
<dependency>
<groupId>maven-spring.example</groupId>
<artifactId>your-package</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
- Add a reference to the package repository. Sample xml is provided below. The Product Team will update the value for id as appropriate.
<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>
In this example, the variable CI_SERVER_URL will be the URL of the Gitlab server, and MAVEN_PACKAGE_PROJECT_ID will be the Gitlab project number of the package repository you are pulling the package from.
B. Add a ci_settings.xml file. A sample is provided below.
<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>
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.
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 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"