I've run into a situation where configuring Nexus as a Mirror for everything doesn't quite suit my needs. My Nexus repository is behind a VPN. If I can't access the Nexus repository, I can't build anything because it's configured as a Mirror. What if I want to build a project that has no dependencies on my Nexus repository yet I can't access it? This would build fine by simply using the Central repository but it won't look there because of the Mirror.
Does anyone have any ideas on how to get around this? I think ideally I'd like to look at Nexus first but if it's not accessible I'd like to look at the Central repository. I'm also open to any other suggestions for achieving the same goal that anyone may have.
you need to configure multiple repositories
http://maven.apache.org/guides/mini/guide-multiple-repositories.html
maven-3.0.4\conf\settings.xml file could be configured this way:
<?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">
<pluginGroups />
<proxies />
<servers>
<server>
<!-- local repository have restricted access -->
<id>central</id>
<username>myusername</username>
<password>mypassword</password>
</server>
<server>
<id>LocalRepository</id>
<username>myusername</username>
<password>mypassword</password>
</server>
</servers>
<mirrors>
<mirror>
<id>central</id>
<mirrorOf>external:*</mirrorOf>
<name>Central</name>
<url>url to repository</url>
</mirror>
<mirror>
<id>LocalRepository</id>
<mirrorOf>LocalRepository</mirrorOf>
<name>repository</name>
<url>url to repository</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>central</id>
<repositories>
<repository>
<id>central</id>
<name>Central</name>
<url>http://central/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>LocalRepository</id>
<name>specific repository</name>
<url>repository URL</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>central</activeProfile>
</activeProfiles>
</settings>
The best approach for this kind of requirement is to run Nexus locally on your development machine.
Its easy to install and run and you can just always point to it.
Configure it to proxy your corporate Nexus and Central.
Then when you are off the VPN .. the corporate proxy repo will just be unreachable but you still get anything else just fine. Nexus manages it all for you.
I have been doing this for years and it allows me to switch to different contexts all the time very easily. It is a bit of a standard practice for many Maven users in fact and should be for other tools that use remote repositories like Gradle or SBT as well. Makes things a LOT easier.
Related
I have a spring-boot application (myapp) with drools the kie-ci module enabled (the drools version i use i the 7.13.0.Final).
I also host my kjars to a remote nexus maven repository.
KieScanner is not fully operative with remote nexus repository.
At the time of project building for first time, all the κjars are detected and downloaded in my local maven repo but when myapp is running the remote updated kjars are not detected by kiescanner.
When i manually delete the local kjars from the .m2 repository, then the latest kjars are downloaded locally and kiescanner detects them.
Seems to be more a maven issue than a drools issue.
My settings.xml maven file is the following:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>central</id>
<name>central</name>
<url>http:///XXX.XXX.X.ΧΧ:8081/repository/maven-group/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>myprofile</id>
<repositories>
<repository>
<id>maven-snapshots</id>
<url>http://XXX.XXX.X.ΧΧ:8081/repository/maven-snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
and i execute myapp by the following format:
java -jar -Dspring.profiles.active=myprofile target/myapp-0.0.1-SNAPSHOT.jar
How i can make myapp to detect remote nexus updated kjars dynamically?
Thank you very much for you time!
I am in a closed network, do not have access to http://repo.maven.apache.org We set up a Nexus server and we download all of our .m2's on a publicly accessible computer, burn to disk, then upload to our Nexus server (inefficient but necessary)
Currently I am trying to set up the system to only use my nexus server, currently it tries to go to http://repo.maven.apache.org
(assuming is set to false) If I have set to true, it does not even attempt to go to my private repo. Basically, I just need my Maven to only look at my nexus instance, not even attempt to go to http://repo.maven.apache.org
Here are portions of my settings.xml and pom.xml files:
<!-- Settings.xml in my .m2 directory -->
<offline>true</offline>
<servers>
<server>
<id>mynexus</id>
<username>xxx</username>
<password>xxx</username>
</server>
<server>
<id>mynexusplugins</id>
<username>xxx</username>
<password>xxx</username>
</server>
</servers>
<!-- pom.xml -->
<repositories>
<repository>
<id>mynexus</id>
<url>http://192.168.100.4:8081/....</url>
</repository>
</repository>
<pluginRepositories>
<pluginRepository>
<id>mynexusplugins</id>
<url>http://192.168.100.4:8081/....</url>
</pluginRepository>
</pluginRepository>
Add your repository as mirror of all in the settings.xml, this way it won't look any other repo.
<mirrors>
<mirror>
<id>yourRepo</id>
<name>yourRepo name</name>
<url>your url</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
https://maven.apache.org/guides/mini/guide-mirror-settings.html
As a side note, If you set offline in maven(via command line or config) it will only use local m2 folder.
I setup a public repository in nexus which contains the groups of repositories we wish to access. We then use this as our main index in Eclipse for development and Bamboo for build.
I am adding in a couple of ZK repositories to this public repository - these repos have no indexes, and are unable to be scraped by Nexus. I presume this will prevent artifacts in them from being found. I have rebuilt the index for public in Nexus and in Eclipse with no luck.
Can I add the repositories in the setting.xml in eclipse? Currently this looks like the following:
<?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>nexus</id>
<username>username</username>
<password>xxxx</password>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://<ip>:8400/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>
Search indexes are an optional repository feature. They are not used for artifact retrieval, they are used to support interactive search in UI's. Nexus will be able to pull artifacts from these proxy repositories without any problem. As artifacts are downloaded from the remote into the proxy repository's disk cache they will be added to the local search index.
The last few days I was trying to set a maven-development environment up. We're using TeamCity for the CI, SonarQube for analysis and SonaType Nexus for the repository management.
TeamCity and SonarQube are working like a charm - The nexus however gives us lots of trouble.
This kind of set up is nothing special, I've done it several times now. This time however, I got a very weird bug: TeamCity is able to deploy artifacts to the nexus, but gives an org.apache.maven.wagon.authorization.AuthorizationException: Not authorized , ReasonPhrase:Unauthorized. error when reading dependencies from the nexus.
I even tried changing the user that TeamCity uses from deployment to admin, same issue. chown returned the correct values as well (owned by the "buildagent" user).
I seriously have no clue what could cause this issue, I already tried reinstalling the nexus 3 times, even added the admin role to the "deployment" user - no change whatsoever.
The settings.xml the "buildagent" user uses has the following content (passwords marked with XXX):
<servers>
<!-- This is the username password used to access the nexus repository -->
<server>
<id>central</id>
<username>deployment</username>
<password>XXX</password>
</server>
<server>
<id>rn-releases</id>
<username>deployment</username>
<password>XXX</password>
</server>
<server>
<id>rn-snapshots</id>
<username>deployment</username>
<password>XXX</password>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<url>http://build.example.com:8301/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>
<activeProfile>nexus</activeProfile>
</activeProfiles>
For your information: The build log from TeamCity states that the settings are getting read correctly as well, so that's not the cause either.
I really would like to fix this asap, since we have developers waiting to continue on their projects (and we don't want to give out the url if it's not secured, we have private projects running on the CI).
Thanks in advance!
Edit:
So I now even tried installing artifactory - and I still have the same issue. It seems to be something with either A: Maven or B:TeamCity.
The mirror to Nexus has the id nexus, but there's no <server>-entry with this id. If you add that to the settings.xml with the correct credentials, it should all work again.
We have multiple repositories in Nexus (i.e., releases, snapshot and site). All 3 repos are under public group and users uses the same credentials to access all these repositories. Providing the same username and password in settings.xml for each repository makes it redundant and hard to maintain them.
Could you please suggest an elegant way to describe one server credential for all the 3 repositories?
Any help is greatly appreciated.
We are using maven 2.2.1 and Nexus OSS 2.7.1
Here is my settings.xml
<settings>
<servers>
<server>
<id>snapshot</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>release</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>site</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>
<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>
Just use one entry in setttings.xml like that
<server>
<id>nexus</id>
<username>deployment</username>
<password>deployment123</password>
</server>
and then in distributionManagement in your pom.xml's you use something like that
<distributionManagement>
<repository>
<id>nexus</id>
<name>Nexus Releases</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Nexus Snapshot</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
For fully working setup with this look at the Nexus Book Examples project that are used in the trial guide. You can add a site with the same id as well, of course. Keep in mind that there is no problem if the id;s are the same as they just detail the identifier of the server element in settings to look for and are NOT an id element for the repository. Imho it should be called serverId or something to be clearer, but thats a different story.
Not a solution but a workaround:
settings.xml will handle system properties and environment variables. So if you're not fussed about putting your server authentication details in a script or in your environment, you can stick with three server credentials but eliminate the need to update all three of them in favour of updating your script or environments (I've put examples for both options in this snippet):
<servers>
<server>
<id>releases</id>
<username>${env.NEXUS_USERNAME}</username> <!-- Env var -->
<password>${nexus.password}</password> <!-- System (-D) var -->
</server>
<server>
<id>snapshots</id>
<username>${env.NEXUS_USERNAME}</username> <!-- Env var -->
<password>${nexus.password}</password> <!-- System (-D) var -->
</server>
<server>
<id>site</id>
<username>${env.NEXUS_USERNAME}</username> <!-- Env var -->
<password>${nexus.password}</password> <!-- System (-D) var -->
</server>
</servers>
Unfortunately there's no <properties> element supported in settings.xml!
Aside: maven already handles the snapshots and releases repositories within nexus, and that is the better way to do things. Your posted settings.xml even enables them already. Why do you need separate repository entries for snapshots and releases?
It looks like you mistaken things here. The given credentials and id's are for the distributionManagement and not for the access to the Nexus in this case. Apart from that you need three different username, password combinations cause you have three possible things releases, snapshots and site. So not a big deal.
Aprt from that i would suggest to upgrade Maven into Maven 3.X line cause Maven 2.2.1 is a little bit out of date.