adding multiple repositories in maven settings xml - maven

I have tried to refer two repository from nexus in the setting.xml file, but it fails at first url and does not go to the next one. is there a mistiake in my xml.(nexus group does work, but we want to know the solution of how to work with diff repo in setting xml)
<settings>
<servers>
<server>
<id>maven</id>
<username>username</username>
<password>password</password>
</server>
<server>
<id>jenkins</id>
<username>username</username>
<password>password</password>
</server>
</servers>
<mirrors>
<mirror> <!--This sends everything else to /public -snapshots-->
<id>maven</id>
<mirrorOf>*</mirrorOf>
<url>https://nexus_example.net/repository/Maven_Proxy/</url>
<!--<url>http://localhost:8081/repository/maven-proxy/</url>-->
</mirror>
<mirror> <!--This sends everything else to /public -snapshots-->
<id>jenkins</id>
<mirrorOf>*</mirrorOf>
<url>https://nexus_example.net/repository/Jenkins_Proxy/</url>
<!--<url>http://localhost:8081/repository/maven-proxy/</url>-->
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>maven</id>
<url>https://nexus_example.net/repository/Maven_Proxy/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>jenkins</id>
<url>https://nexus_example/repository/Jenkins_Proxy/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>

Your first mirror is a <mirrorOf> everything, and so the second mirror is never used.

Related

How to set up maven?

How to set up Maven (settings.xml) and Artifactory to access all repositories through Artifactory?
My current settings are as follows and I even fail to get the Maven-deploy plugin
to execute. The error is that it was not found in any repos (local + artifactory)
<?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>xxx</username>
<password>xxx</password>
<id>central</id>
</server>
<server>
<username>xxx</username>
<password>xxx</password>
<id>snapshots</id>
</server>
</servers>
<mirrors>
<mirror>
<mirrorOf>*</mirrorOf>
<name>repo</name>
<url>http://[host]:[port]/artifactory/repo</url>
<id>repo</id>
</mirror>
</mirrors>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://[host]:[port]/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://[host]:[port]/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://[host]:[port]/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://[host]:[port]/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
[host]:[port] are real in file and so is [username][password] checked that 3 times.
[ERROR] No plugin found for prefix 'deploy' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\[username]\.m2), repo (http://[host]:[port]/artifactory/repo)] -> [Help 1]
Artifactory can generate the right settings.xml file for you. Look for Maven Settings link on the right side menu of the home screen.

Using Nexus repository instead of public Maven in Idea Intellij

How can I force Idea Intellij to download from Nexus repository instead of Maven Public repo?
Where can I configure that in Idea properties?
It's not defined in pom.xml files and I'd prefer not to.
Not sure if it will work also on Idea Intellij ( I am using spring source studio - eclipse clon) , but should because maven configuration is in settings.xml in .M2 directory which is located in your home directory. Just use something like this ( my server is running on nexus-server:8081):
<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">
<servers>
<server>
<id>releases</id>
<username>user-name</username>
<password>your-password</password>
</server>
<server>
<id>snapshots</id>
<username>user-name</username>
<password>your-password</password>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://nexus-server:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Disable 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>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>

Prefetch maven-metadata.xml with nexus

With the maven3 configuration file settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<!--<host>webproxy</host>-->
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://richter-local.de:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<servers>
<server>
<id>nexus</id>
</server>
</servers>
<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>
<updatePolicy>interval:10080</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>interval:10080</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>interval:10080</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>interval:10080</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
<interactiveMode>true</interactiveMode>
<usePluginRegistry>false</usePluginRegistry>
<offline>false</offline>
</settings>
and a nexus maven proxy (version 2.7.2-03) I have to wait for a bunch of very slow downloads of maven-metadata.xml file every day after 00:00 a.m. (take about 5 mintues together for some KB which ought to be transfered within seconds). How can I prefetch those file in order to download them my local nexus instance?
It sounds like you have one or more proxy repositories that have remotes that are responding very slowly. Once a day the cache timeouts for these expires, resulting in very slow retrieval.
See here for information on how to debug this, and configure Nexus to prevent the issue from occurring again:
https://support.sonatype.com/entries/25884097-Troubleshooting-slow-maven-metadata-xml-download-speeds

How to disable usage of public maven repo

I've setup a maven repository(Artifactory) in my LAN which has no internet access. I've also change my maven settings.xml to use this internal repo only. However when I try to create a maven project, it still try to access the public repo(http://repo1.maven.org/maven2) for some downloads. Where has I done wrong?
For example, when I perform the following:
mvn archetype:generate -DgroupId=demo.john -DartifactId=struts2demo
-DarchetypeGroupId=org.apache.struts
-DarchetypeArtifactId=struts2-archetype-starter
-DinteractiveMode=false
there is the following waring reported:
... ...
[INFO] Generating project in Batch mode
[WARNING] Error reading archetype catalog http://repo1.maven.org/maven2
org.apache.maven.wagon.TransferFailedException: repo1.mavne.org
at org.apache.maven.wagon.shared. ...
... ...
Sometimes the it build successfully with this waring, but sometime it won't.
Below is my maven's settings.xml
<?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>
<id>central</id>
<username>admin</username>
<password>password</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>password</password>
</server>
</servers>
<mirrors>
<mirror>
<id>my-company-repo</id>
<name>A maven repo in local network</name>
<url>http://my.internal.server/artifactory/repo<url>
</mirror>
<mirrorOf>*</mirrorOf>
</mirrors>
<profiles>
<profile>
<id>artifactory</id>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://my.internal.server/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://my.internal.server/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://my.internal.server/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://my.internal.server/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>

Can't compile Spring Roo project when using Nexus

Can't compile Spring Roo (1.2.3.RELEASE) project when using Nexus.
mvn says can't find roo.annotations:jar
[ERROR] Failed to execute goal on project Roo123: Could not resolve dependencies for project com.example.roo:Roo123:jar:0.1.0.BUILD-SNAPSHOT: Failure to find org.springframework.roo:org.springframework.roo.annotations:jar:1.2.3.RELEASE in http://192.168.16.232:8081/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced -> [Help 1]
However this jar is already in local maven repository.
When disabling Nexus, by renaming .m2\settings.xml, it works fine.
settings.xml has just 1 mirror configured
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.16.232:8081/nexus/content/groups/public</url>
</mirror>
How to configure Nexus?
(Adding http://spring-roo-repository.springsource.org/release as proxy repository doesn't help)
UPDATE: add picture. Adding spring-roo-repository on the left side doesn't help.
Two long answeres below doesn't help either.
It's not enough to configuration a mirrorof only you have to configure the following:
<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>
Apart from your configuration you need to delete your local repository and retry the build. Have you configured Nexus correctly to have access to the internet like maven central etc. ?
I don't know if you have admin access to your Nexus install, but you have to add a new proxy repository to your Nexus install.
The repo you have to add is
http://spring-roo-repository.springsource.org/release
You should have a settings file like below (slightly different than khmarbaise's version):
<settings
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>central</id>
<username>your-user</username>
<password>your-user</password>
</server>
<server>
<id>mirror</id>
<username>your-user</username>
<password>your-user</password>
</server>
</servers>
<mirrors>
<mirror>
<id>mirror</id>
<url>https://url.to.your.nexus</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>defaultprofile</id>
<repositories>
<repository>
<id>central</id>
<name>Repository for your artifacts</name>
<url>https://url.to.your.nexus</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Repository for your artifacts</name>
<url>https://url.to.your.nexus</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
<activeProfiles>
<activeProfile>defaultprofile</activeProfile>
</activeProfiles>
</settings>
You have to override central (see above), so that Maven won't connect to the default central (repo1.maven.org).

Resources