Maven project use multiple GitLab Package Registry - spring-boot

I am trying to setup 2 GitLab projects (project a & project b) as the remote maven repository for my other project (project c) using GitLab Maven Package Registry.
Now I have 2 GitLab Maven Package Registry
project A -> id : 112233
project B -> id : 445566
So, now I need to set the registry setup in my project C pom.xml file
How I can do that, because we can't have multiple in our pom.xml file
<!--registry setup for project a-->
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/112233/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/112233/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/112233/packages/maven</url>
</snapshotRepository>
</distributionManagement>
<!--registry setup for project b-->
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/445566/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/445566/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/445566/packages/maven</url>
</snapshotRepository>
</distributionManagement>

If project A and B sit in the same group, then you shall use the group-level Maven endpoint in project C's pom.xml:
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.example.com/api/v4/groups/GROUP_ID/-/packages/maven</url>
</repository>
</repositories>
Else, I guess you should be able to specify one repository for each:
<repositories>
<repository>
<id>gitlab-maven-a</id>
<url>https://gitlab.com/api/v4/projects/112233/packages/maven</url>
</repository>
<repository>
<id>gitlab-maven-b</id>
<url>https://gitlab.com/api/v4/projects/445566/packages/maven</url>
</repository>
</repositories>
/!\ Don't forget to set your Maven authentication credentials in your settings.xml file in either case (unless your project has public visibility).
Prefer using the CI_JOB_TOKEN.

Related

How to prevent Maven from downloading artifacts from repository when I just update the pom version of my project

I'm using Maven as CI and JFrog Artifactory as a repository of my own artifacts and as a cache. Everything works fine. I'm using the Artifactory plugin in Jenkins to trigger artifact download and upload.
I cannot figure how to handle the following use case.
I have a multi-module project. In my Settings.xml I defined some snapshot, plugin, and release repositories.
In my local workspace, I upgraded the pom version of the parent project and its children. Then I made a local clean install. It failed because Maven was trying to download the artifacts of my project from Artifactory and they don't exist of course because I'm trying to create a new version of the project.
How to handle this use case? How to configure my pom or settings to do?
How to do this in the Artifactory plugin in Jenkins in a freestyle way?
I have error messages like this :
10:23:28 Failed to transfer Could not find metadata com.xxx.xxxx.xxx:my-parent-project:3.0.0-SNAPSHOT/maven-metadata.xml in xxx
10:23:50 [FATAL] Non-resolvable parent POM for com.xxx.xxxx.xxx:subpoject1:[unknown-version]: Could not find artifact .....and 'parent.relativePath' points at wrong local POM # line 7, column 10*
=====================================
pom configuration of the parent pom
<modelVersion>4.0.0</modelVersion>
<groupId>com.xxx.xxx.xxx</groupId>
<artifactId>my-parent-project</artifactId>
<version>3.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>../subproject-1</module>
<module>../subproject-2</module>
</modules>
==================================
pom configuration for subproject1
<artifactId>subproject-1</artifactId>
<parent>
<groupId>com.xxx.xxx.xxx</groupId>
<artifactId>my-parent-project</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
======================================
Here is my settings.xml configuration
<profile>
<id>artifactory_profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://xxxxxxxxxxxx:8081/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://xxxxxxxxxxxx:8081/artifactory/libs-snapshot</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>sing</id>
<name>sing-virtual-repo</name>
<url>http://xxxxxxxxxxxx:8081/artifactory/virtual-repo</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://xxxxxxxxxxxx:8081/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-release</name>
<url>http://xxxxxxxxxxxx:8081/artifactory/plugins-release</url>
</pluginRepository>
</pluginRepositories>
</profile>
If you run clean install on the parent POM, then everything will be created correctly.

Artifactory OSS throwing 405 Exception when running maven release:perform

artifactory-oss-6.7.2 is throwing a 405 status code exception when running maven release:perform
Created a settings.xml from artifactory "generate settings.xml" on repo. All repos are virtual repos. Added distributionManagement to my project pom file to use the ids for snapshots and releases from settings.xml.
settings.xml:
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://localhost:8081/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://localhost:8081/artifactory/libs-snapshot</url>
</repository>
</repositories>
myproject/pom.xml:
<distributionManagement>
<repository>
<id>central</id>
<name>Artifactory Release Repo</name>
<url>http://localhost:8081/artifactory/libs-release</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Artifactory Snapshot Repo</name>
<url>http://localhost:8081/artifactory/libs-snapshot</url>
</snapshotRepository>
</distributionManagement>
run mvn release:perform output:
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project model: Failed to deploy artifacts: Could not transfer artifact com.test:model:jar:0.1.0 from/to central (http://localhost:8081/artifactory/libs-release): Failed to transfer file http://localhost:8081/artifactory/libs-release/com/srcrea/model/0.1.0/model-0.1.0.jar with status code 405 -> [Help 1]
So I followed something I found here -> http://forums.jfrog.org/Error-Code-405-with-mvn-deploy-td7174367.html
And updated DistributionManagement of the pom.xml
<distributionManagement>
<repository>
<id>central</id>
<name>Artifactory Release Repo</name>
<url>http://localhost:8081/artifactory/88888</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Artifactory Snapshot Repo</name>
<url>http://localhost:8081/artifactory/88888</url>
</snapshotRepository>
</distributionManagement>
Re-Run and now I see it:
But what is not clear is in order to generate settings.xml you need to associate virtual repos to a local repo. Then generate settings off that and use the distributionManagement configuration to point back to the local repo. What is the point of the virtual repo?

how to exclude artifact from deploy in specific profile

in our pom file we have a special profile that allow us to deploy artifacts to both our internal maven repo as well as external one which locate on google cloud.
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>nexus</id>
<name>Internal Releases</name>
<url>http://internal_instance_ip/nexus/content/repositories/releases</url>
<layout>default</layout>
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>nexus-snapshots</id>
<name>Internal Snapshots</name>
<url>http://internal_instance_ip/nexus/content/repositories/snapshots</url>
<layout>default</layout>
</snapshotRepository>
</distributionManagement>
<profiles>
<profile>
<id>gce</id>
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>nexus-gce</id>
<name>External Releases</name>
<url>https://gce_instance_ip/content/repositories/releases</url>
<layout>default</layout>
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>nexus-snapshots-gce</id>
<name>External Snapshots</name>
<url>https://gce_instance_ip/content/repositories/snapshots</url>
<layout>default</layout>
</snapshotRepository>
</distributionManagement>
</profile>
</profiles>
when I tried to deploy the project, it complained :
Return code is: 413, ReasonPhrase: Request Entity Too Large.
the project has lots of modules, the one that cause trouble doesn't need to be deployed to google cloud. How can i exclude that module from being deployed to the google cloud repo but still deployed to the internal repo?
You can exclude the module by passing the following argument on the command line:
--projects '!module-to-exclude'
From mvn --help:
-pl,--projects <arg> Comma-delimited list of specified
reactor projects to build instead
of all projects. A project can be
specified by [groupId]:artifactId
or by its relative path.
See also How to exclude a module from a Maven reactor build?

Maven multiple repositories in pom but "Missing artifact" with JBoss repository

I've added two repositories to my pom:
<repositories>
<repository>
<id>objectify-appengine</id>
<url>http://objectify-appengine.googlecode.com/svn/maven</url>
</repository>
<repository>
<id>jboss</id>
<url>http://repository.jboss.org/maven2</url>
</repository>
</repositories>
but get 'Missing artifact ...' for all dependencies except jboss.(can't get dependencies from central and objectify)
Tried to add repositories to the settings.xml. But no effect.
What wrong?
Your repository is deprecated, update it this way :
<project >
<repositories>
<repository>
<id>JBoss Public repository</id>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
</project>

mvn:install to place my jar in nexus remote repository

I am using maven in eclipse (m2 eclipse)
When i execute mvn:install i want my jar(artifact) to be installed in the nexus repository which is located on the server(right now the installed jar is placed in the local system repository).. how can i do that ?
I even changed this to my local repository address
Typically, you'd use mvn deploy to deploy to a non-local repository.
You will, of course, need to have the repo configured, either in your maven settings.xml or in the project POM.
As we always use the same internal repo, I've done this in the Maven settings.xml, more precisely, the "profiles" section.
Here is my config for reference:
<profiles>
<profile>
<id>artifactory</id>
<repositories>
<repository>
<id>central</id>
<name>libs-releases</name>
<url>http://repo.example.com/libs-releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<name>libs-snapshots</name>
<url>http://repo.example.com/libs-snapshots</url>
<snapshots />
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>plugins-releases</name>
<url>http://repo.example.com/plugins-releases</url>
<snapshots><enabled>false</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>

Resources