Maven not using local repository - java

I have a small problem with my Maven config. All other questions and answers here didn't solve my problem, so I'm starting a new question.
My problem is, that my Maven is not using the local repository. It's always fetching the artifacts from the remote repositories.
When an artifact is downloaded or when I build a project it is installed in the local repository, so the path is correct.
The problem is: When I build one SNAPSHOT project, it is only installed in the local repository (should be like this, don't want to publish it on my nexus every time). When I build another project having the previous one as dependency in the pom.xml maven wants to download the artifact from the nexus server where it didn't find it instead of taking it from the local repository.
This is my maven config:
<?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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>C:\Users\Marc\.m2\repository</localRepository>
<interactiveMode>false</interactiveMode>
<usePluginRegistry>false</usePluginRegistry>
<pluginGroups>
</pluginGroups>
<servers>
<server>
<id>releases</id>
<username>MY_USERNAME</username>
<password>MY_PASSWORD</password>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
</server>
<server>
<id>snapshots</id>
<username>MY_USERNAME</username>
<password>MY_PASSWORD</password>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
</server>
<server>
<id>nexus</id>
<username>MY_USERNAME</username>
<password>MY_PASSWORD</password>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
</server>
</servers>
<profiles>
<profile>
<id>nexussrv</id>
<repositories>
<repository>
<id>snapshots</id>
<url>http://nexus/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>releases</id>
<url>http://nexus/content/repositories/releases</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>nexus</id>
<url>http://nexus/content/groups/public</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexussrv</activeProfile>
</activeProfiles>
</settings>
Downloading from the nexus and publishing artifacts (SNAPSHOT and RELEASE) to the nexus work with this config but it doesn't use artifacts from the local repository.
Thanks for your Help!

You've configured that the SNAPSHOTs should always (<updatePolicy>always</updatePolicy>) be downloaded from your snapshot-nexus. So even if your local cache (the ~/.m2/repository) has a newer version of the snapshot, maven tries to download it from the configured server (http://nexus/content/repositories/snapshots).
Think about changing the updatePolicy for the snapshot-entry. E.g. if you have a CI-server which deploys a SNAPSHOT daily (in the morning) to the snapshot-nexus, change the updatePolicy to daily.

If you change you'r config to <updatePolicy>always</updatePolicy>, it still will attempts to download from the nexus, because you have to disable nexus config in pom.xml
mind that <reposotiry> tag in your pom.xml will take precedence over what's defined in your settings.xml

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

Maven failing to build when not connected to company VPN / private repository?

With a lot of people working from home currently and using VPNs, I am having an issue with building on maven for personal projects that don't use work related artefacts.
Which results in me always needing to be connected to the VPN.
For example if I create a new spring boot application, it requires me to be on the VPN otherwise it won't be able to build properly, with an error like this:
Failed to read artifact descriptor for
com.hubspot.slack:slack-base:jar:1.8: Could not transfer artifact
com.hubspot.slack:slack-base:pom:1.8 from/to at-repository
(https://foobar.jfrog.io/foobar/public): Access denied to:
https://foobar.jfrog.io/foobar/public/com/hubspot/slack/slack-base/1.8/slack-base-1.8.pom
Is there a way for me to configure maven to try and build without the need for my company repository?
Or can I have multiple configs and a way to switch between them?
I understand it should fail for foocompany specific artefacts but not everything else.
This is the config.xml (redacted name)
<?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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>foo-repository</id>
<url>https://foo.jfrog.io/foo/public</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<servers>
<server>
<id>foo-repository</id>
<username>deployment</username>
<password>xxx</password>
</server>
<server>
<id>snapshots</id>
<username>deployment</username>
<password>xxx</password>
</server>
<server>
<id>releases</id>
<username>deployment</username>
<password>xxx</password>
</server>
</servers>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>foo-repository</id>
<url>This has to be populated but the URL will be taken from the mirror.</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>foo-repository</id>
<url>This has to be populated but the URL will be taken from the mirror.</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
Essentially it was a case of disabling the user maven config like so and using a bash alias to make it easier
#turn off default settings
mv ~/.m2/settings.xml ~/.m2/settings.xml.off
#turn on again
mv ~/.m2/settings.xml.off ~/.m2/settings.xml
More info on my workaround can be seen here:
https://tomaytotomato.com/maven-whilst-working-from-home/

Jenkins Config File Maven Multiple Nexus Repositories Download

So I want to setup a config file in Jenkins for a Maven project to use multiple repositories. The whole idea is to try and download from one if it cannot be found then download from the second one. Below is what I have configured now and from the Jenkins logs, I can see it 'downloading' from both repositories.
The problem is that it doesn't actually fallback if it can't find it in the first one it simply fails so something is wrong. I have to add that everything works fine if I use either of them exclusively so it's not a connectivity issue are anything else like that. Please help I have been at this for a day and a half now and I am fairly sure it's because I can't wrap my mind around the Maven Documentation.
[INFO] Downloading: https:NEW_NEXUS/artifact/1.15.0-SNAPSHOT/maven-metadata.xml
[INFO] Downloading: http:OLD_NEXUS/artifact/1.15.0-SNAPSHOT/maven-metadata.xml
[INFO]
<?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
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>new-nexus</id>
<mirrorOf>*</mirrorOf>
<name>New Nexus Repository</name>
<url>NEW_NEXUS/nexus/repository/maven-public/</url>
</mirror>
<mirror>
<id>old-nexus</id>
<mirrorOf>old-nexus</mirrorOf>
<name>Old Nexus Repository</name>
<url>OLD_NEXUS/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>new-nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>old-nexus</id>
<name>Old Nexus Repository</name>
<url>OLD_NEXUS/nexus/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>new-nexus</activeProfile>
</activeProfiles>
</settings>
By using
<mirrorOf>*</mirrorOf>
you set the repository as mirror of everything, so every request is redirected to the NEW_NEXUS/nexus/repository/maven-public repository.
What you usually do:
Go into the Nexus as administrator and define a repository group which contains both repositories. Then just use this repository group as mirror of everything. The Nexus repository group behaves as you expect: It goes through all the repositories until it finds the requested artifact.

Why does maven build only when the Nexus Anonymous user is active?

I am building my code using maven and we have our repositories on Nexus. The only way I manage to run a successfully mvn install from the command console is when I enable the Anonymous user from the Nexus settings.
In order to make sure I have all the needed rights I added in the settings.xml the admin user.
<settings>
<servers>
<server>
<id>serverIDblabla</id>
<username>NexusAdminUser</username>
<password>NexusAdminPass</password>
</server>
</servers>
<profiles>
<profile>
<id>myIDblabla</id>
<repositories>
<repository>
<id>repositoryID</id>
<url>https://.../repository/myrepository/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
...
I use:
apache maven 3.2.1
Nexus 3.0.0 -03
Any suggestions?

JFrog Artifactory and Oracle repository

I've started to use JFrog Artifactory 4.14, my maven app needs an ojdbc jar which can be downloaded from oracle repository, which, if I use maven local settings, I'd setted from
http://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9010
Now, using JFrog Artifactory, I've setted remote repo according to
http://buttso.blogspot.lt/2015/02/fronting-oracle-maven-repository-with.html https://www.jfrog.com/blog/fronting-oracle-maven-repository-artifactory/
TEST button says connection successful
I've replaced settings.xml file with the one JFrog Artifactory generated to me
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<username>${security.getCurrentUsername()}</username>
<password>${security.getEscapedEncryptedPassword()!"*** Insert encrypted password here ***"}</password>
<id>central</id>
</server>
<server>
<username>${security.getCurrentUsername()}</username>
<password>${security.getEscapedEncryptedPassword()!"*** Insert encrypted password here ***"}</password>
<id>snapshots</id>
</server>
</servers>
<mirrors>
<mirror>
<mirrorOf>*</mirrorOf>
<name>remote-repos</name>
<url>http://docker.k***.l**:8081/artifactory/remote-repos</url>
<id>remote-repos</id>
</mirror>
</mirrors>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://docker.k***.l**:8081/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://docker.k***.l**:8081/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://docker.k***.l**:8081/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://docker.k***.l**:8081/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
I've added to my POM
<distributionManagement>
<repository>
<id>central</id>
<name>e44b4c0db643-releases</name>
<url>http://docker.k***.l**:8081/artifactory/ext-release-local</url>
</repository>
</distributionManagement>
but when I try to run maven command
clean install
I get
The following artifacts could not be resolved: com.oracle.jdbc:ojdbc7:jar:12.1.0.2, com.oracle.jdbc:ucp:jar:12.1.0.2: Could not find artifact com.oracle.jdbc:ojdbc7:jar:12.1.0.2 in remote-repos
You need to define a virtual repository in JFrog. This will be a combination of other repositoies, this is the one you will point at in your settings.xml.
See https://www.jfrog.com/confluence/display/RTF/Virtual+Repositories
I suspect you will also need a proxy element in your settings.xml.
See https://maven.apache.org/guides/mini/guide-proxies.html
As You already have created You new Remote Repository You have to add it to Virtual Repository
choose New (or edit existing one)
and select repositories
that should be it

Categories

Resources