Maven project only downloading from internal artifactory (pom.xml) - java

I have a local Java intelli-J project with a pom.xml that has (2) internal repositories on artifactory. The problem is I am doing some testing, and I think one of the JARs is not on this internal repo, so I want to use the regular Maven central repo. I googled and believe, the artifact should go through the list in your pom.xml is the order its listed and try to resolve the artifact, the problem is, even when I add the Maven central repo, it seems to never attempt; only tries the internal artifactory then fails.
In my pom.xml:
<repositories>
<repository>
<id>test</id>
<name>Maven Central</name>
<layout>default</layout>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>my_repo</id>
<name>MyRepo</name>
<url>https://myinternalrepo.com</url>
</repository>
<repository>
<snapshots />
<id>MySnapShotRepo</id>
<name>MyInternalRepo</name>
<url>https://myinternalreposnapshots.com</url>
</repository>
</repositories>
am I doing something wrong here?

I removed my settings.xml and was able to control the repositories from the pom.xml file tag. It also looks like maven repo is automatically tried whether you list it or not in pom .

Related

Maven failing to download artifact from central repository

I have two private JFrog repositories setup. One repository handles releases and the other handles snapshots. Here is how I have defined this in my settings.xml file.
<settings>
<activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
<servers>
<server>
<id>central</id>
<username>private-repo-username</username>
<password>private-repo-password</password>
</server>
<server>
<id>snapshots</id>
<username>private-repo-username</username>
<password>private-repo-password</password>
</server>
</servers>
<profiles>
<profile>
<id>default</id>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>a0d2olsx0t222-artifactory-primary-0-releases</name>
<url>https://my-private-repo.jfrog.io/artifactory/libs-release</url>
</repository>
<repository>
<id>snapshots</id>
<name>a0d2olsx0t222-artifactory-primary-0-snapshots</name>
<url>https://my-private-repo.jfrog.io/artifactory/libs-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
Multiple of my internal dependencies in my multi-module maven project are getting this error:
[ERROR] Failed to execute goal on project platform-utils: Could not resolve dependencies for project
design.colspalinva:platform-utils:jar:2.2.1-SNAPSHOT: The following artifacts could not be resolved:
com.maxmind.geoip2:geoip2:jar:2.12.0, org.apache.ant:ant:jar:1.10.5: Could not find artifact
com.maxmind.geoip2:geoip2:jar:2.12.0 in central (https://my-private-repo.jfrog.io/artifactory/libs-
release) -> [Help 1]
From the look of it, it doesn't appear that Maven is trying to reach out to the official Maven Central repo for those dependencies, rather failing on my private repository. I was under the impression that if the private repository does not contain the specific artifact, it will attempt to reach out to Maven Central.
It has no problem downloading my Spring dependencies from Maven Central.
If you like to redirect all access of central from Maven to your own repository manager you have to configure the settings.xml as follows:
<! language:language-xml ->
<?xml version="1.0" encoding="UTF-8"?>
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://IP:PORT/repository/repo</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
The Maven settings.xml configuration you shared seems to be OK. You are overriding the built-in central and snapshot repositories of Maven, which is the correct way to make sure that Maven send requests by default to Artifactory.
Adding a Mirror Any setting, as suggested in the other answer, means that in addition to overriding built-in Maven repositories, you can use the Mirror Any setting to redirect all requests to a Maven repository through Artifactory, including those defined inside POMs of plug-ins and third party dependencies.
According to the log you shared Maven does attempt to resolve the artifacts via Artifactory - https://my-private-repo.jfrog.io/artifactory/libs-release
The issue seems to be related to resolution of a specific artifact(s)in Artifactory.
I'm assuming that libs-release is a virtual Maven repository and that it contains at least one remote Maven repository pointing at Jcenter or Maven Central (if not please start by looking at Maven Repositories).
To debug the issue:
(1) Try resolving the artifact directly from Artifactory using cURL or a web browser, for example:
curl -Uuser:pass https://my-private-repo.jfrog.io/artifactory/libs-release/com/maxmind/geoip2/geoip2/2.12.0/geoip2-2.12.0.jar
(2) If you manage to resolve the artifact, it mean that Artifactory is properly configured and Maven should be able to resolve. If not, try looking for the reason performing a trace, for example:
curl -Uuser:pass https://my-private-repo.jfrog.io/artifactory/libs-release/com/maxmind/geoip2/geoip2/2.12.0/geoip2-2.12.0.jar?trace

Adding remote repository jar file as dependency in pom.xml maven

Is it possible to add remote repository jar file (https://repo.ah/lib/abc.jar) in maven pom.xml as dependency in java project. if so, can you please share example.
No, it's not possible to add a complete repository as a dependency. This doesn't make sense, because a repository can contain ten thousands of artifacts.
If your project requires artifacts which are not hosted in the standard remote repository, you can specify this via the <repositories> tag in your pom.xml .
<repositories>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
<repository>
<id>vaadin-snapshots</id>
<url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
More Informations:
Introduction to Repositories
Setting up Multiple Repositories
In the comments you mentioned that the URL is an Artifactory.
So just add the Artifactory as <repository> to your settings.xml and then you can use the jar in your application.

How can I make maven to use maven cetral repo?

So my default maven settings.xml file in my ~/.m2/ folder is containing links to my work repositories. So whenever I run an install on my pom.xml's it try to fetch from the corp nexus maven repositories.
For a hobby project which I am just starting with I don't want to make use of the corp maven nexus, but to make use of the central maven repo. I don't want to replace the entire settings.xml as this would mean reloading the entire local maven repo once I switch back to my corp work.
How can I achieve this ?
Add the following as your first repository in the repositories tag in the settings.xml
<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
</repository>
You may also want to use profiles. But, that is not a requirement.
You can also add a repository on your pom
<repositories>
<repository>
<id>central</id>
<url>http://rep1.maven.org/maven2</url>
</repository>
</repositories>

Adding additional repository to Maven 3

I want to add to my project some special dependeny from some repository.
For this I add the repository in my pom:
<repositories>
<repository>
<id>jenkins-repo</id>
<name>Jenkins Repository</name>
<url>maven.jenkins-ci.org/content/repositories/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
.. and in the same file add the dependency:
<dependency>
<groupId>org.jvnet.com4j</groupId>
<artifactId>com4j</artifactId>
<version>20120426-2</version>
</dependency>
But it doesn't work: the dependency is not found. As far as I understand this proves that the dependency exists in the right place:
http://maven.jenkins-ci.org/content/repositories/releases/org/jvnet/com4j/com4j/20120426-2/
So here are the questions:
1) Where I went wrong?
2) If I add repository to pom the default repository still be checked?
3) The link provided is really a link to Maven repo which proves I can download an artifact from it?
change <url> to include protocol
<url>http://maven.jenkins-ci.org/content/repositories/releases</url>

How can I prevent Maven from checking for updates from repositories that I don't list in my settings.xml file?

In my settings.xml file I have listed repositories that I want Maven to use (see the file below). These repositories are located in the build machine and I am working this way to prevent a build fail when there's is no Internet connection in the build machine.
The problem is that Maven automatically looks for updates in the central repository (and possibly from other non-listed repositories) during the build. Is there a way to prevent this behaviour?
...
<profile>
<id>myProfile</id>
<repositories>
<repository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<updatePolicy>never</updatePolicy>
</snapshots>
<id>myRepo</id>
<url>file://${my.home}/maven/.m2/repository</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<updatePolicy>never</updatePolicy>
</snapshots>
<id>myRepo</id>
<url>file://${my.home}/maven/.m2/repository</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
</profile>
...
Note: Using the offline option (e.g. -o flag) is not an option for me. What I really want is Maven to use only the repositories that I list in my settings.xml file.
Every Maven project inherits the configuration for the central repository from the Maven Super POM. You can use Maven's mirrors feature to redirect calls to central to your preferred repository. You do this by adding some configuration to your settings.xml like this:
<settings>
...
<mirrors>
<mirror>
<id>central-proxy</id>
<mirrorOf>central</mirrorOf>
<url>http://myrepository/releases</url>
</mirror>
</mirrors>
..
</settings>
This configuration can either be put in your user settings (${user.home}/.m2/settings.xml) or global settings ({$M2_HOME}/conf/settings.xml).
Set your desired repositories as a mirror of everything else.
More details: http://maven.apache.org/guides/mini/guide-mirror-settings.html

Categories

Resources