Repository mirroring - maven

I'm starting with maven and is not all clear what to put in mirror <mirrorOf></mirrorOf> tag.
What I understood:
1> * means "everything"
2> ! prepended to a name exclude that name from look-up path
3> central is used whan mirroring maven central
Now what I want to do is to mirror a repository that is not maven central (teamdev's one in my case), hence I have no idea towards what the field should match: com.teamdev, jxbrowser or com.teamdev.jxbrowser
this is what is listed on temadev website as maven repo:
<repository>
<id>com.teamdev</id>
<url>https://europe-maven.pkg.dev/jxbrowser/releases</url>
</repository>
and
<dependency>
<groupId>com.teamdev.jxbrowser</groupId>
<artifactId>jxbrowser-cross-platform</artifactId>
<version>7.21.2</version>
<type>pom</type>
</dependency>

Each artifact stored in some maven remote repository, and to have it as dependency we should include this repository definition to the project pom.xml.
Most artifacts available in Central repository and it's defined per each pom.xml by super-pom.
com.teamdev
On this page
temadev website mentioned, that in order to use this dependency:
<dependency>
<groupId>com.teamdev.jxbrowser</groupId>
<artifactId>jxbrowser-cross-platform</artifactId>
<version>7.21.2</version>
<type>pom</type>
</dependency>
you have to add
<repository>
<id>com.teamdev</id>
<url>https://europe-maven.pkg.dev/jxbrowser/releases</url>
</repository>
to your pom.xml <repositories>...</repositories>.
Adding a mirror
And if you want to specify another location (artifacts download url) for com.teamdev repository-id, you may specify it in your pom.xml without mirroring.
But if your dependency contains some <repository> and downloads transitive dependencies from it, you have to add a mirror to specify another url.
in your settings.xml file add:
<settings>
...
<mirrors>
<mirror>
<id>com.teamdev-mirror</id>
<name>com.teamdev Mirror Repository</name>
<url>https://your-repository-url</url>
<mirrorOf>com.teamdev</mirrorOf>
</mirror>
</mirrors>
...
</settings>
is not all clear what to put in mirror tag
<mirrorOf>com.teamdev</mirrorOf> matches the <id>com.teamdev</id> in repository definition.
And this artifact jxbrowser-cross-platform should be available in your https://your-repository-url mirror with all other dependencies from the original repository.
And you have to refer your settings.xml file when run maven commands, e.g. if settings.xml present in the project root:
mvn clean compile -s settings.xml
or see more about settings reference here.

Related

Maven not pulling dependency from correct repository

I have 3 repositories setup in our Nexus Repository manager
COMPANY_maven-proxy -> proxies https://repo1.maven.org/maven2/
COMPANY_maven-redhat-proxy -> proxies https://maven.repository.redhat.com/ga/
3rd-Party-Tools -> our companies homegrown 3rdParty dependencies
When I run the mvn install command it pulls everything I'm looking for from each of these repositories (the dependency itself and the transitive dependencies). All except for one!
org.jboss.seam.integration:jboss-seam-int-jbossas:pom:7.0.0.GA
This dependency lives in the Redhat maven repository:
<dependency>
<groupId>org.jboss.seam.integration</groupId>
<artifactId>jboss-seam-int-jbossas</artifactId>
<version>7.0.0.GA</version>
<type>pom</type>
</dependency>
For whatever reason, this one dependency is looking under the COMPANY_maven-proxy repository instead of the COMPANY_maven-redhat-proxy repository.
Here's what I have for my settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<mirrors>
<mirror>
<!--This sends everything to COMPANY_maven-proxy that isn't in COMPANY_maven-redhat-proxy -->
<id>COMPANY_maven-proxy</id>
<url>http://FQDN:8081/nexus/repository/COMPANY_maven-proxy/</url>
<mirrorOf>*,!COMPANY_maven-redhat-proxy</mirrorOf>
</mirror>
<mirror>
<!-- This sends everything to COMPANY_maven-redhat-proxy that isn't in COMPANY_maven-proxy -->
<id>COMPANY_maven-redhat-proxy</id>
<url>http://FQDN:8081/nexus/repository/COMPANY_maven-redhat-proxy/</url>
<mirrorOf>*,!COMPANY_maven-proxy</mirrorOf>
</mirror>
<mirror>
<!--This sends everything else to 3rd-Party-Tools -->
<id>3rd-Party-Tools</id>
<url>http://FQDN:8081/nexus/repository/3rd-Party-Tools/</url>
<mirrorOf>!COMPANY_maven-proxy,!COMPANY_maven-redhat-proxy</mirrorOf>
</mirror>
</mirrors>
</settings>
Here's the error I get:
Failed to collect dependencies at org.jboss.seam.integration:jboss-seam-int-
jbossas:pom:7.0.0.GA: Failed to read artifact descriptor for org.jboss.seam.integration:jboss-
seam-int-jbossas:pom:7.0.0.GA: Could not find artifact org.jboss.seam.integration:jboss-seam-
int:pom:7.0.0.GA in COMPANY_maven-proxy (http://FQDN:8081/nexus/repository/COMPANY_maven-proxy/) -> [Help 1]
I've tried multiple combination's within the <mirrorOf> tag but nothing has worked. I've even put this transitive depency in my pom under <dependencies> and/or <dependencyManagement>.
Any help on this would be appreciated!
Thanks!
The mirrors are for already existing repositories declared. In your settings.xml you do not have repositories listed, but the default Maven Central. Thus it makes sense to define just a mirror of Maven Central, redirecting to the company's Nexus repo. with a rare trick, one could register a mirror for any external repos, for example:
<mirror>
<id>public</id>
<mirrorOf>central</mirrorOf>
<name>Let the default Maven Central repository is resolved in the local Nexus' public repository</name>
<url>http://FQDN:8081/nexus/repository/COMPANY_maven-proxy/</url>
</mirror>
Any mirror from your example should be registered in the pom.xml as repositories.
Edited:
removed the second ("other") mirror, as the example was adapted from a case where the repository manager to direct to runs at localhost.

Specifying the maven repository URL for getting the dependencies resolved?

I am trying to understand how maven downloads the binaries from the repositories.
For example, I have the following dependency for my project:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.7.1</version>
</dependency>
Now, these binaries are present in http://mvnrepository.com/.
In pom.xml, we have <repositories> tag where we specify the repository URL from where maven can download the files, template:
<repositories>
<repository>
<id>mvnrepository_id</id>
<name>mvnrepository.com</name>
<url></url>
</repository>
Now, my doubt is, what should be the value of the <url>; does it need to be the base url , like http://mvnrepository.com/ or the complete URL --> http://mvnrepository.com/artifact/org.apache.hadoop/hadoop-hdfs
To me it appears that is should be the base url else for each dependency we have to put the complete URL.
Can anyone help me understand this?
Unless you want to fetch artifacts from a repository different from the default Central Maven repository, you need not add the <repositories> section to your pom.xml. Read about Maven Repositories here and here.
And the url for default Central Maven repository is http://repo.maven.apache.org/maven2/.
PS: The URLs you have posted are the ones for the Website.

Downloading dependency using a custom repository

My company just created a custom repository. I am trying to download a dependency I added to the repository, but the jar doesn't seem to get added to my .m2 directory.
Maven isn't throwing any errors during the install.
Here is the repository in the POM file:
<repositories>
<repository>
<id>snapshots</id>
<url>http://[domain]/artifactory/libs-snapshot</url>
</repository>
</repositories>
and the dependency:
<dependency>
<groupId>com.adobe.aem.sql</groupId>
<artifactId>mysqlAEM</artifactId>
<version>1.0.0-20170313.175547-1</version>
</dependency>
Have also replaced the timestamp with SNAPSHOT.
The path within the repository is:
http://[domain]/artifactory/libs-snapshot-local/com/adobe/aem/sql/mysqlAEM/
And i know the setup of where the JAR file is a little wonky, but I will fix that once I can get it downloaded to my local maven repository.

Maven unable to download from remote repository

I'm trying to build a Maven module that depends on SVNKit.
So my pom.xml looks like this:
<dependencies>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.3.7</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>tmatesoft-releases</id>
<url>http://maven.tmatesoft.com/content/repositories/releases/</url>
</repository>
</repositories>
When I try to do a mvn clean install, it looks like it attemps to look into a Nexus repository, and obviously cannot find it. I'm obviously trying to download the artifact from a remote repository at: http://maven.tmatesoft.com/content/repositories/releases
I took a look at my settings.xml file in my ~/.m2/ folder and I see that there is a mirror that looks like this:
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://Our_Nexus_Repository</url>
</mirror>
I thought that, if you define a <reposotiry> tag, your module's pom.xml will take precedence over what's defined in your settings.xml file.
Any help is appreciated. Thank you.
this is because the mirror will mirror all the repositories, : <mirrorOf>*</mirrorOf>
you can change replace it like this : <mirrorOf>*,!tmatesoft-releases</mirrorOf>
more info please visit : http://maven.apache.org/guides/mini/guide-mirror-settings.html
With the way that you're using the mirror statement in your settings.xml, you're directing maven to always go to your repository. If that is indeed the behavior that you wish, you should create a proxy for the tmatesoft-releases repository inside your nexus installation.
A common methodology for doing this is to setup a repository group for all releases you wish to have on your nexus installation. Then just add proxy repos to the group as needed, and users won't need to change their settings.xml to instantly have visibility to the new repos you add.

Should I write repositories in my pom.xml?

I am new to Maven. If I start new project with Maven, should I know any repository URLs for it to work?
For example, this Hibernate tutorial http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html says about how to create a sample project with pom.xml text. But this pom.xml does not contain any repositories.
So, my m2eclipse plugin says, for example Project build error: 'dependencies.dependency.version' for org.hibernate:hibernate-core:jar is missing., for all dependency tag in pom.xml
Is this because of repositories absence?
Where to know repositories URLs? Is there one big repository? Why doesn't it included by default?
UPDATE 1
It is said here, that Maven should use "central" repository by default: http://maven.apache.org/guides/introduction/introduction-to-repositories.html
I have searched there for hibernate-code artifact and found it. So, this artifact IS in central repository. By my maven says dependency not found. Hence it doesn't use it's central repository. Why?
Apparently your Hibernate dependency is missing <version> tag:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.9.Final</version> <!-- this line is missing -->
</dependency>
Note that you don't have to specify version of dependencies previously declared in <dependencyManagement>.
Old answer:
Every build script (not only with Maven) should be reproducible and independent from environment. Standard pom.xml (called super pom), which every pom.xml inherits from, already defines main Maven central repository:
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
You don't have to define this repository, and you don't have to define any others if all your dependencies are there. On the other hand if you are using some external repositories, you must add them to pom.xml, so that every developer is always able to build.
The bottom line is: if you can build the project having a completely empty repository, your pom.xml is fine.
It's not advisable to define repositories in POM files as that causes a lot of issues (Maven will search those repositories for ANY artifact even the ones available at Central, poor portability, ...)
Best approach: Setup a repository manager (Artifactory, Nexus) and edit your settings.xml file to use the repo manager as a mirror.
Second best approach: Define the required repositories in your settings.xml file, not in your pom.xml files.
Repositories in poms is a bad idea.

Resources