Nexus is not caching maven central plugins - maven

Im using Maven 3.0.4 and Nexus 2.0.6. I have set up my settings.xml as the Nexus instruction show for using a single repository.
I get the error below when maven tries to run maven -U clean.
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its d
ependencies could not be resolved: Failed to read artifact descriptor for org.ap
ache.maven.plugins:maven-clean-plugin:jar:2.4.1: Could not find artifact org.apa
che.maven.plugins:maven-clean-plugin:pom:2.4.1 in nexus (http://localhost:8081/n
exus/content/groups/public) -> [Help 1]
If I remove the nexus mirror from the settings and go directly to maven central the command works. The settings for the maven repo in nexus show that it is in service and it is in the public group (its listed last).
I am not behind a proxy to access the internet.
Here is my settings.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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<offline>false</offline>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>maven-central</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>

Make sure the Central proxy repository is properly configured, and the proxied URL is http://repo1.maven.org/maven2/. Check that you can see cached artifacts at the repository's URL, should be http://localhost:8081/nexus/content/repositories/central/org/apache/maven/plugins/maven-clean-plugin/2.4.0/maven-clean-plugin-2.4.1.pom.
Make sure you have a Central proxy at all, is there anything listed at http://localhost:8081/nexus/content/repositories/central/.
If you're behind a proxy, you can configure the proxy under the Default HTTP Proxy Settings (optional) section in the Administration->Nexus pane.
Then, make sure the Public Repositories group repository is configured to include the Central repository in its list of included repositories.
If everything looks fine so far, check the logs, maybe there's a helpful message in there.

Try downloading this directly through a web browser:
http://localhost:8081/nexus/content/groups/public/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom
If this doesn't work check the sonatype-work/nexus/logs/nexus.log file for more information about the failure.

I had the same symptom as the OP (Nexus was not mirroring an artifact) and found that it was caused by a route definition.
For example, you have an artifact org.blabla:blabla-api:1.0 which is in Maven Central. However you have set up a route matching .*/org/blabla/.* that forces any matching requests to look only in the proxied repository blabla-public ... but unfortunately blabla-public doesn't contain that particular artifact.
Solution: either update the route to add Central to the list of repos used by the route, or delete the route.
(This probably wasn't the cause for the OP, but I'm posting it in case it helps any other visitors.)

Related

How to use Sonatype Nexus as a mirror for Ivy dependencies [duplicate]

This question already has answers here:
Use public maven repository with ivy
(3 answers)
Closed 7 years ago.
Id like to use Sonatype Nexus as a company-internal maven/ivy repository. My goal is that every request goes to nexus, and if nexus does not (yet) contain the requested artifact, it should delegate the request to the official maven repository. All artifacts that were downloaded from the official maven repository should be saved on nexus (as a backup). In addition, I want to be able to save my own artifacts the server for other project to use them (e.g. internal libraries)
In a past project, we have set up a Sonatype Nexus server to be used as a mirror for the maven repository which worked fine. Now I'm struggeling with an project which uses Ivy to accomplish the same with the existing nexus installation.
In the maven project, we had the following in settings.xml
<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">
<interactiveMode />
<usePluginRegistry />
<offline />
<pluginGroups />
<servers>
<server>
<id>deployment</id>
<username>[USERNAME]</username>
<password>[PASSWORD]</password>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://mavenserver:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</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>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
How can I accomplish the same with Ivy?
As long as you are using Ivy to access Maven repositories and not some custom defined Ivy format you can use the approach documented in the Nexus Repository Manager documentation.
Also check out the examples project for a working example.
And if you are using Ant you can also use Eclipse Aether instead of Ivy. More to that also in the docs and examples.

Is there such a thing as a local remote Maven repository?

I have a build box on which is installed:
Maven
Bamboo
Archiva
I have configured Bamboo to grab my Maven project from a remote Git source and then build it with the goals 'clean install'.
I have configured Archiva with two repos:
mirror - a mirror of central
dev - repo for my artifacts
I have made the following changes to Maven settings.xml:
# Define local repo - this is the same location as i have set up for the Archiva 'dev' repo.
<localRepository>/opt/maven-repo/dev</localRepository>
# Define the Archiva mirror i set up
<mirror>
<id>mirror</id>
<url>http://localhost:8080/repository/mirror/</url>
<mirrorOf>external:*</mirrorOf>
</mirror>
When I execute the build Maven grabs everything external via the mirror and then adds the built artifact to dev, along with the other jars it grabbed from mirror. So i now have some duplicate jars...
\repo\mirror\junit\junit
\repo\mirror\classworlds\classworlds
\repo\dev\junit\junit
\repo\dev\classworlds\classworlds
\repo\dev\me\myartifact
My question is, is the correct approach? Really I want to keep 'dev' with just my artifacts and mirror with everything from central - i don't want duplicates.
Should I be using the LocalRepository config in settings.xml or should I be using 'mvn deploy' to put the artifact in my Archiva repository by a different method?
Could someone clarify the different use cases for a local and remote repository?
Finally, how should I be defining my POM? Currently, I have just defined
<distributionManagement>
<repository>
<id>dev</id>
<url>file:///repo/dev</url>
</repository>
</distributionManagement>
Should i be adding in my mirror?
To put artifacts in your repository manager you should use the default which is maven-deploy-plugin which can be controlled by distributionManagement. The target where to put those things is controlled by defining the distributionManagement.
<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/xsd/maven-4.0.0.xsd">
...
<distributionManagement>
<repository>
<id>releases</id>
<name>Release</name>
<url>http://urlArchiva/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshots</name>
<url>http://urlArchiva/snapshots/</url>
</snapshotRepository>
...
</distributionManagement>
...
</project>
The repositories which are used to consume artifacts from is defined in the settings.xml
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://serverUrlArchiva/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</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>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
On Bamboo you should be able to control which settings.xml is used to have an local repository per build which makes build independent from each other.

How to fetch artifacts from own repo using maven?

How do I create a simple project that fetches artifacts from my repo using maven? And where will these artifacts get saved to - my default maven repo?
I am using Apache Archiva.
Just simply start using a repository manager like Nexus and that's it. Please configure your settings.xml file according to the following:
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>URL OF your ARCHIVA SERVER</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</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>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
The artifacts which are being downloaded are first stored into the Archiva and of course on your hard drive $HOME/.m2/repository.
If you like to deploy artifact into archiva you need to configure the distributionManagement in your pom file similar like this:
<distributionManagement>
<repository>
<id>releases</id>
<name>Archiva RElease repo</name>
<url>http://URL OF YOUR ARCHIVA/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots<id>
<name>Archiva Snapshots repo</name>
<url>http://URL OF YOUR ARCHIVA/snapshots/</url>
</snapshotRepository>
...
</distributionManagement>
...
To test this you can use mvn deploy to see if the artiacts are being deployed to the snapshot repository. You can change the version of your test project into 1.0 and redo a mvn deploy which will try to deploy the artifacts into the release repository.

What does "http://central" mean in my Maven settings.xml?

I've been copying "sample" settings.xml files for ages now, and almost all of them seem to include a repository with the URL http://central. This bugs me, because of course there could actually be a machine on the local domain called "central", so this is a valid URN, but it also must (might?) have some special meaning to Maven.
Is it just shorthand that's commonly used, but the actual URL is ignored? Could I replace it with something else, or remove it entirely? Is it documented anywhere?
If it matters, I develop on a corporate network that has an internal iBiblio mirror, that acts as "central" for us.
AFAIK, it is a bogus URL which mentions at Configure Maven to Download from Nexus as the following example: -
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</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>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
The nexus profile is configured to download from the central repository with a bogus URL of http://central.
This URL is overridden by the mirror setting in the same settings.xml file to point to the URL of your single Nexus group. The nexus group is then listed as an active profile in the activeProfiles element.
I hope this may help.
We also used exactly this sample config, even with the same comments for about 15(!) years without any problems. For maven builds it does not matter, as always nexus is requested for any dependencies.
But today I tried to built a project with a combined ant+maven build which failed to get dependencies via artifact:remoteRepository Task from central Repo.
The solution was to fix the "url" tag in the central repo: https://repo.maven.apache.org/maven2
So it looks like it doesn't matter in most cases, but to avoid any corner cases, always use the right url.

How do I configure maven to access maven central if nexus server is down?

I would like to setup my build such that it automatically attempts to download an artifact from maven central iff our nexus server is unreachable. I have the following in settings.xml and I'm not sure how to change it (if even possible).
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://mynexus</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://mynexus</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
In order to use a repository manager (Nexus included) you need to have a mirrorOf * element defined that will intercept all the repository urls and send them to Nexus for resolution. In Maven2 and 3, the mirrorOf element is not able to be configured in a profile. This means there is no easy way to flip back and forth without changing your settings.
You would need to comment out the mirrors section and then deactivate the Nexus profile to have Maven revert back to standard behavior.
Fortunately though Nexus is very stable and it should never go down.

Resources