My situation:
I basically need clientside implementation Artifactory virtual repos.
We are being forced to use GitLab (self-hosted) for package management for each project, and an entirely different package manager (nexus) for public artifacts. For all sorts of reasons outside this discussion, using a group repo in nexus is out of the question.
This means that I MUST configure maven client side to resolve packages with 2 different repositories: So, something like org.apache.*
would resolve with maven central, and com.mycompany
would resolve with the project specific repo. And I need/want to do this so it’s super portable and simple, so it can build on a user machine or build in a CI/CD pipeline that is also in the process of moving from 1 GL instance to another.
The idea is that, when I type mvn install
it will check maven central, see that GAV FOO:BAR:1.0.0
doesn’t exist and fall back to the internal repo.
I know these artifacts are ok because in my testing I have mirrored to *, and created a virtual/group repo. I now know I can’t do that for reasons, hence I need to configure this sort of behavior client side.
How can this be achieved?
1
Unless I’m not understanding the question properly, this is a basic functionality of maven. You can define a repositories
element in a pom or your settings file and list as many repository
s in it as you want. Doing so in the pom would be more portable:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
...
<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
<repository>
<id>jitpack</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>company-repo</id>
<url>https://repo.company.com/maven2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-library</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
3
You can configure the repositories in settings.xml file of Apache Maven
-
Create a new settings.xml file in your project root folder or you can also modify your global maven configuration by updating the settings.xml file in {ApacheMaven}/conf/settings.xml file
-
By default, Maven will look for the libraries in the order in which they are specified.
-
Giving below an example configuration for one internal repo with the backup repo as the maven public repo.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<repositories>
<repository>
<id>nexus</id>
<name>Nexus Repository</name>
<url>http://your-nexus-server/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<mirrors>
<mirror>
<id>central</id>
<mirrorOf>*</mirrorOf>
<url>https://repo1.maven.org/maven2/</url>
</mirror>
</mirrors>
</settings>
You create a settings.xml
that contains all the relevant repositories. Maven then automatically checks them all in order.
Be careful, though, with the <mirror>
definition. If you define a mirror of *
, it will draw EVERY request.