0

I recently updated my Spring Boot apps development setup for a multi-module maven project

  • MainProject
    • AMQP
    • APIGateway
    • EurekaServer
    • Customer
    • Fraud

Then I have this structure in GitLab:

  • Group - Main Folder
    • Infra - Subgroup
      • EurekaServer - project repository
      • APIGateway - project repository
    • Services - Subgroup
      • AMQP - project repository
    • Shared - Subgroup
      • Customer - project repository
      • Fraud - project repository

Now I'd like to build the EurekaServer in CI but it needs to know where to locate the parent POM (which is only stored in my local machine). How can I configure this to GitLab so that succeeding build to other modules can lookup into the registry for the parent POM and other dependency modules? Should I create a repository only for the parent POM and pull that in the CI job?

I found this question during my research but this only works in local machine. Maven Modules + Building a Single Specific Module

UPDATE: I have this existing configuration for both the parent and module POMs.

<repositories>
  <repository>
    <id>gitlab-maven</id>
    <url>https://gitlab.com/api/v4/groups/GROUP-ID/-/packages/maven</url>
  </repository>
</repositories>
<distributionManagement>
  <repository>
    <id>gitlab-maven</id>
    <url>https://gitlab.com/api/v4/projects/PROJECT-ID/packages/maven</url>
  </repository>
  <snapshotRepository>
    <id>gitlab-maven</id>
    <url>https://gitlab.com/api/v4/projects/PROJECT-ID/packages/maven</url>
  </snapshotRepository>
</distributionManagement>

First, from the project root folder I executed this command to push the parent artifact into the registry mvn deploy -N -s settings.xml and succeeded.

Next, build docker image for the module (AMQP). Here's the CI config

stages:
  - deploy

push-to-registry:
  stage: deploy
  image: maven:3.8.1-jdk-11-slim
  script:
    - mvn deploy -s settings.xml
  tags:
    - configuration

and this is the error log

[FATAL] Non-resolvable parent POM com.xyz:services:1.0-SNAPSHOT for com.xyz.module:amqp:[unknown-version]: Failure to find com.xyz:services:pom:1.0-20220114.024427-3 in https://gitlab.com/api/v4/groups/GROUP_ID/-/packages/maven was cached in the local repository, resolution will not be reattempted until the update interval of gitlab-maven has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 5, column 11
Rye
  • 445
  • 4
  • 15
  • You not to push the parent pom file to your Gitlab repository and refer it? Since it's a part of the multi-module project. I believe it's much easier to work with the multi-module project when all the files are within a single repository. – Max Daroshchanka Jan 14 '22 at 05:52
  • 1
    There is a repo for the parent pom which only contains the `settings.xml` and `pom.xml`. I used the command `mvn deploy -N -s settings.xml` to push the artifact to its registry. For the module, I have setup the `pom.xml` to locate the parent and got this error. `Non-resolvable parent POM com.abc:services:1.0-SNAPSHOT for com.abc:eurekaserver:[unknown-version]` – Rye Jan 14 '22 at 05:57
  • If you already deployed the parent POM to the maven repository, your module should try to download it as an external dependency (if cannot find the file locally), so, make sure that your module pom has access to the maven repository which keep your parent pom. – Max Daroshchanka Jan 14 '22 at 06:19
  • 1
    Do you mean, you deploy maven artifacts to the GitLab Package Registry and need help how to configure this? – Max Daroshchanka Jan 14 '22 at 06:29
  • Yes, is it correct that I passed the `-N` in parent `mvn deploy` or I really need to build them first in the parent? Because the problem now it can locate the parent but not the module since it was skipped when parent was deployed. – Rye Jan 14 '22 at 06:59
  • `mvn deploy -N -s settings.xml` for parent pom is correct. In this way your parent pom will be available as dependency for other modules. Do you use group-level or instance-level maven registry endpoint as I suggested in my answer? – Max Daroshchanka Jan 14 '22 at 07:04
  • Yes, I have that existing configuration. (updated the question) – Rye Jan 14 '22 at 07:36
  • Do you follow this? For the id, use what you defined in settings.xml. For GROUP_ID, use your group ID, which you can view on your group’s home page. For PROJECT_ID, use your project ID, which you can view on your project’s home page. Replace gitlab.example.com with your domain name. – Max Daroshchanka Jan 14 '22 at 07:39
  • Seems you have not replaced the placeholders with your real ids. – Max Daroshchanka Jan 14 '22 at 07:41
  • 1
    Yes, I used the `gitlab-maven` in settings `server.id` and in pom.xml `repository.id` – Rye Jan 14 '22 at 07:45
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/241058/discussion-between-max-daroshchanka-and-rye). – Max Daroshchanka Jan 14 '22 at 07:48

1 Answers1

0

Based on this documentation: https://maven.apache.org/pom.html#Inheritance

Reference to local file is optional.

Notice the relativePath element. It is not required, but may be used as a signifier to Maven to first search the path given for this project's parent, before searching the local and then remote repositories.

So, you have to deploy the parent POM project first.

And after this, your sub-modules will be able to resolve the parent POM dependency.

Just make sure, there is access to the maven repository which stores parent POM.

Using GitLab Package Registry

If the project uses GitLab Package Registry for publishing artifacts, use

group-level-maven-endpoint

or

instance-level-maven-endpoint

for Maven repository configuration.

The project-level-endpoint configuration will not allow sharing artifacts.


Reference

https://docs.gitlab.com/ee/user/packages/maven_repository/

Max Daroshchanka
  • 2,698
  • 2
  • 10
  • 14