Nexus server with unexpected behavior - maven

I've installed a local nexus on my computer to use it as a mirror of the numerous nexus servers that my company have.
I think it's working because if I access the following URL oin my browse:
http://localhost:2312/repository/my_repo/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
It's show the content of the .pom file.
But when I run mvn clean install on prompt, I got the following:
Failed to transfer file: http://localhost:2312/repository/my_repo/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom. Return code is: 504 , ReasonPhrase:Gateway Timeout.
On my maven settings.xml I put this:
<mirrors>
<mirror>
<id>Nexus</id>
<name>Nexus Local</name>
<url>http://localhost:2312/repository/my_repo/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
What am I missing?

Have you setup your settings.xml like this:
<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>

Related

Specify a specific repository url in maven settings.xml to deploy in Nexus

I'm a new guy on Maven and Nexus.
I have a problem to deploy my maven project (developped with IntelliJ) on my local Nexus.
You will find attached my maven settings.xml
My objective is to deploy my project without modify a pom.xml file, only the ~/.m2/settings.xml
I have tried the following command (which works) :
$ mvn clean deploy -DaltDeploymentRepository=nexus::default::http://192.168.1.8:8081/repository/maven-snapshots
But I want the same results with only :
$ mvn clean deploy
Any idea ?
Thanks
<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>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.1.8:8081/repository/maven-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>
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>******</password>
</server>
</servers>
</settings>
You can add a <properties> section to your settings.xml and add
<altDeploymentRepository>nexus::default::http://192.168.1.8:8081/repository/maven-snapshots</altDeploymentRepository>

set to NOT connect to specific nexus repository

There is on nexus repository which my application always connects in the building process. I don't find where this repository is set so:
is it possible to set in the pom.xml that do not connect to a specific repository?
settings.xml file is the correct location to configure this.
<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>

Multiple repositories not being searched for maven

In my settings.xml I have configured this -
<mirrors>
<mirror>
<id>lon33881xus</id>
<name>Project Nexus Repo</name>
<url>http://lonrs08358:9093/nexus/content/groups/public</url>
<mirrorOf>central,maven2-repository.dev.java.net,thirdparty1</mirrorOf>
</mirror>
<mirror>
<id>lon80813</id>
<mirrorOf>*</mirrorOf> <url>http://lon3388x1us:1083/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://lonrs03296:1081/nexus/content/repositories/riskit_common_snapshot/</url>
</mirror>
<!--<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://m2.neo4j.org/content/repositories/releases/</url>
</mirror> -->
</mirrors>
But still when the maven build runs only the 1st repository is seahced for jars and then the build fails as it is unable to find jars which are present in 2nd repository. I want jars to be searched in 1st repo and if not found then in 2nd. I am new to maven please help.
The best option here is configure your local nexus to use http://m2.neo4j.org/content/repositories/releases. Add this site to nexus as proxy.
Then your configuration should be like this:
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://lonrs08358:9093/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>
After that all actions are done behind the scene. When your local nexus does not have library it will download from proxy and then you should receive that library also in your local repo.

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.

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