maven - multiple repository lookup configuration - maven

I'm using maven v3.0.1 for my projects. I've projects which depends on artifacts from a corporate remote repository. Also I had a local archiva repository in company which hold local artifacts, which are not in to corporate remote repository.
I would like to make the settings.xml in such a way that for all projects, it will lookup for the specified artifact first in the corporate remote repository, if not found there, look up for the artifact in the local archiva repository.
I added local repository in <repository> tag and enabled the profile for that <activeProfile>. But the looking up is not happening as expected. On analysis found that mirrorOf setting plays a role there. Following are my settings.xml.
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://corporate-repo:8081/nexus/content/groups/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>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
<repository>
<id>spring-snapshot</id>
<name>Spring Maven SNAPSHOT Repository</name>
<url>http://repo.springsource.org/libs-snapshot</url>
</repository>
<repository>
<id>internal</id>
<name>Local Release Repository</name>
<url>http://local-repo:8081/repository/internal</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
How can I modify the settings.xml to do the lookup as I required ? Whether any way to provide two urls in the mirrorOf settings. I tried
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://corporate-repo:8081/nexus/content/groups/public,http://local-repo:8081/repository/internal</url>
</mirror>
No errors in xml parsing, but lookup is not working. Can any one shed light on how to resolve this issue

I experimented with lot of options and finally resolved by tweaking the mirrorOf settings to <mirrorOf>*,!internal</mirrorOf>
So mirror settings are,
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*,!internal</mirrorOf>
<url>http://corporate-repo:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
* ensures that for all request except internal repo !internal do lookup in corporate repo. For internal repo, do look up in local-repo configured with repository id as internal

Related

maven getting "Not Authorized" when trying to access nexus private repository

I've set up a private nexus repo manager on an EC2 instance and followed the various instructions floating around the internet on how to set up a maven project to use it. I have also disabled the anonymous account.
I am able to connect and copy repositories via curl -U username:password <the_url>
and it seems to work fine. However when I try to use maven (any goals) The very first thing I get is
[WARNING] Could not transfer metadata org.apache.maven.plugins:maven-compiler-plugin/maven-metadata.xml from/to nexus (http://MY_NEXUS_HOST:8081/nexus/content/groups/public): Not authorized , ReasonPhrase:Unauthorized.
The mvn command then fails because it can't find the plugin anywhere. So the fact that I can use the rest command and it works as expected, but not through maven indicates to me that it is a problem with the configuration. I think I understand what's going on pretty well, and I've checked and rechecked the files, but I don't see anything wrong.
Here's the settings.xml file
<servers>
<server>
<id>nexus-snapshot</id>
<username>USER_NAME</username>
<password>USER_PASSWD</password>
</server>
<server>
<id>nexus-release</id>
<username>USER_NAME</username>
<password>USER_PASSWD</password>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://MY_NEXUS_HOST: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>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
And here is the relevent portion of the pom file
<distributionManagement>
<repository>
<id>nexus-release</id>
<name>Nexus Release Repository</name>
<url>http://MY_NEXUS_HOST:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>nexus-snapshot</id>
<name>Nexus Snapshot Repository</name>
<url>http://MY_NEXUS_HOST:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
I'm wondering if there's a way to see the exact issue I'm running into. For instance, if I'm getting a 401, 403 or (for some reason?) 404.
If someone can please help me I'd be ever so greatful.
Oh, both maven and nexus are the latest versions as of last week.
*edited because no matter how many times you check something before hitting submit...
Oh my funky goat.
The problem was that apparently in settings.xml, the Id field has to be the same as the one in the server field. ie:
<servers>
<server>
<id>nexus-release</id> <---THIS MUST MATCH
<username>USER_NAME</username>
<password>USER_PASSWD</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-release</id> <---THIS
<mirrorOf>*</mirrorOf>
<url>http://MY_NEXUS_HOST:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
I guess it doesn't matter which one I use (they're both the same in this case, but that's not necessarily always true).

Configure nexus to look from local repository in the working directory first

I have a project that it has a directory named repo in which artifacts are stored. When I build it with maven, nexus says that the dependencies cannot be resolved; and when I remove nexus from maven settings, it can find the artifacts.
I want maven to look into this directory before asking nexus, or sth like that, so that I can build this without diactivating nexus every time. How can I do that? My current maven settings (~/.m2/settings.xml):
<settings>
<localRepository>/home/a/.m2/repository</localRepository>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<!--<url>http://nexus.yourdomain.nl/content/groups/public</url> -->
<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>
<!-- if you want to be able to switch to the defaultprofile profile put this in the active profile -->
<profile>
<id>defaultprofile</id>
<repositories>
<repository>
<id>maven.default</id>
<name>default maven repository</name>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>maven.snapshot</id>
<name>Maven snapshot repository</name>
<url>http://people.apache.org/repo/m2-snapshot-repository</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>defaultprofile</activeProfile>
</activeProfiles>
</settings>
Nexus website says the mirrorOf pattern of * causes any repository request to be redirected to this mirror and to your single repository group, which in the example is the public group.
It is possible to use other patterns in the mirrorOf field. A possible valuable setting is to use external:*. This matches all repositories except those using localhost or file based repositories.
Putting external:* instead of * solved my problem.
Update:
Second Solution:
Pass this option to maven works fine too:
mvn -Dmaven.repo.local=/path/to/repo

maven local repository proxy external

I am supporting an Archiva internal repository in an organization where some build environments don't have access to the open internet to fetch dependencies. I thought I could configure Archiva as a mirror for everything external (mirror with mirrorOf set to "external.*,!snapshots") and set it up with proxies so that, if one of my builds asks for something that is not in Archiva, it will use the proxies to go get the dependencies from the external sources I set up with proxies. After that, it would be cached in Archiva and would not have to be fetched from outside.
So I have proxies in my Archiva config for codehaus, sonatype (several), the basic Central, Cloudera for Hadoop stuff etc.; but I can't find a configuration that keeps my builds from trying to go directly to the external sources (which they can't reach) and yet satisfies the things that are not already in my Archiva by using the proxies.
Is there some trick configuration I'm missing here? Or do I need to switch to Artifactory or Nexus to get this kind of functionality?
You need to set the maven settings on each of the build environments to point to your archiva instance.
e.g in $user.home/.m2/settings.xml
<mirror>
<id>InternalMirror</id>
<mirrorOf>*</mirrorOf>
<name>Internal Mirror.</name>
<url>http://archivaserver/archivaPath/</url>
</mirror>
I haven't used Archiva before, but I have done this successfully with Nexus
Switching to a nexus will be moer preferable.
I have attached a settings.xml which can be used for nexus....
<?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>F:\m2\repository</localRepository>
<pluginGroups>
<pluginGroup>org.codehaus.sonar</pluginGroup>
</pluginGroups>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>your-host-id</host>
<port>8080</port>
</proxy>
</proxies>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*,!sonar</mirrorOf>
<url>http://nexus-repo-url/content/groups/public</url>
<name>Nexus</name>
</mirror>
</mirrors>
<profiles>
<profile>
<id>NexusProfile</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.5</jdk>
</activation>
<repositories>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
<id>nexus</id>
<name>default-repos</name>
<url>http://nexus-repo-url/content/groups/default-repos</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
<id>nexus</id>
<name>default-repos</name>
<url>http://nexus-repo-url/content/groups/default-repos</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
<id>nexus</id>
<name>default-repos</name>
<url>http://nexus-repo-url/content/groups/default-repos</url>
</pluginRepository>
<pluginRepository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
<id>nexus</id>
<name>default-repos</name>
<url>http://nexus-repo-url/content/groups/default-repos</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>NexusProfile</activeProfile>
</activeProfiles>
<servers>
<server>
<id>nexus</id>
<username>anonymous</username>
<password>password</password>
</server>
</servers>
</settings>
I recommend you read http://maven.apache.org/guides/mini/guide-mirror-settings.html for configuring your settings.
And I recommend you to use Archiva 1.4 version series which is more performant.
We are currently rewriting the ui see a real sample https://archiva-repository.apache.org/archiva/index.html?request_lang=en .
If you want your own version you must download a snapshot from here: https://builds.apache.org/view/A-F/view/Archiva/job/archiva-all-maven-3.x-jdk-1.6/

Maven Nexus private repository access

I have just set up a nexus repository in my local network. This repository exposes access to the Maven central repository, plus three different private hosted repositories: snapshot, release and ext3rdparty. All these repositories are part of the public group in nexus, which I use as a central access point for all repositories:
http://nexus.server/nexus/content/groups/public/
My problem is: Using NetBeans as development envirnment, I can access to all repositories except the ext3rdparty. i.e. i got a compilation error when I try to build projects which are based on libraries stored in the ext3rdparty repo, and NetBeans can't find / navigate any of the artifacts available in this repository.
I suspect this is a settings.xml / pom.xml problem and not a NetBeans one because as I said, I can access to artifacts that I've released in other repositories, but I can't figure-out what's the problem.
Here is the FULL content of my settings.xml to redirect maven to my own repository:
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://nexus.server/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
<servers>
<server>
<id>nexus</id>
<username>user</username>
<password>***</password>
</server>
<server>
<id>releases</id>
<username>user</username>
<password>***</password>
</server>
<server>
<id>snapshots</id>
<username>user</username>
<password>***</password>
</server>
</servers>
And here is the repositories-related part of my parent pom to allow deployment:
<distributionManagement>
<repository>
<id>releases</id>
<name>Releases</name>
<url>http://nexus.server/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshots</name>
<url>http://nexus.server/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
Any idea of what's wrong ?
Thanks in advance!
EDIT:
Half of a day lost: I finally ended up with removing all dependencies from the ext3rdparty repository, uploading them again to the repository, and updating all indexes and now everything works fine...
Don't really know what was the problem here, but at least the pom and the settings were OK. Thanks for your help.
If you have that sort of problem you can right click on the affected repository in the Repositories list and activate a Repair Index or Update Index and then check the status in the System Feeds for System updates.
Did you add your ext3rdparty repo to your public group?

Maven archetype catalog : specify custom location(s)

I'm deploying a Nexus repository for Maven, and custom archetypes on it.
I would like to execute mvn archetype:generate and be prompted a list of internal + custom archetypes.
The only way I found to prompt custom archetypes (in an ergonomic way, meaning no URL) is to define the archetype-catalog path as a property in the settings. This is not a valid solution because I want several catalogs (and this property cannot be overriden in CLI).
Does anybody have a clue on how to do that ?
Thanks in advance,
[EDIT]
I found an issue report related : http://jira.codehaus.org/browse/ARCHETYPE-273
And I noticed that during archetype:generate, maven tries to reach the central repository :
[DEBUG] Searching for remote catalog: http://repo1.maven.org/maven2/archetype-catalog.xml
[DEBUG] Searching for remote catalog: http://repo1.maven.org/maven2
It ends by a "Connection Timed out" because I did not (and don't want to) specify a proxy...
I don't understand why maven doesn't check nexus catalog...
I also have a Nexus configured to mirror the Maven repositories and thus the remote catalog too.
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://afbwt03:8081/nexus/content/groups/JavaRepo/</url>
</mirror>
and:
<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>
I am able to access the remote catalog only when I use the following Maven command line:
mvn archetype:generate -DarchetypeCatalog=http://afbwt03:8081/nexus/content/groups/JavaRepo
If I don't define the archetypeCatalog variable, I get the same behavior as you do: trying to access the repo1. ... although some mirrors are configured.
You need to have
the property archetypeRepository defined in the active profile in your .m2/settings.xml
the repositories and pluginRepositories redirected to your mirror, on the same id "central".
and of course, the mirror defined
Apache maven documentation on archetype plugin specifies that archetypeRepository is definable user property:
http://maven.apache.org/archetype/maven-archetype-plugin/generate-mojo.html
Your .m2/settings.xml should have these minimal elements
<?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>central</id>
<name>Mirror for maven central</name>
<url>http://mymvnhost:8081/nexus/content/groups/public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>dev</id>
<properties>
<archetypeRepository>http://mymvnhost:8081/nexus/content/groups/public/</archetypeRepository>
</properties>
<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>
<activeProfile>dev</activeProfile>
</activeProfiles>
</settings>
With maven-archetype-plugin:3.1.1 you have to
add/edit archetype-catalog.xml on your repo to list your custom archetypes
edit your settings.xml to add this repo with id archetype.
invoke mvn archetype:generate -DarchetypeCatalog=remote
From https://maven.apache.org/archetype/maven-archetype-plugin/generate-mojo.html :
If you want the catalogs to come from a different repository, please add the following to your settings.xml
<repository>
<id>archetype</id>
<url>https://repository.domain.com/path/to/repo/</url>
</repository>

Resources