I did start with maven stuff like 4 or 5 years ago, in that moment a great friend of mine told me that developers have serious problems when any dependency is plugged off from the internet, I was not aware of that but after some investigation I did notice that they created software that depends on certain versions of jar artifacts and unfortunately… it works with just that version.

Updating dependencies to their latest revisions wasn’t exactly a good move, it requires a lot of time, and sometimes greater revisions tends to deprecate methods that are commonly the pillars of your software.

What if those golden revisions are no longer available at the maven repository? If something happens to our building environment then we will be forced to update everything and that means time and money… plus some layoffs (probably).

The solution: Sonatype Nexus

Sonatype Nexus works as a repository management; let’s say that the nexus goes between your maven project and the repositories. The way we used Nexus was merely basic, technically we were just making a proxy to some repositories and keeping those precious artifact versions in our lab, but Nexus is more powerful that you can possible imagine, if you want a deeper explanation, please go directly to sonatype site, in this post I will cover installation and basic usage.

Requirements for this tutorial

  • A Virtual Machine with a Linux Distribution (I will use Ubuntu 12.10 for my Nexus installation)
  • An eclipse environment with the maven plugin or Maven itself (download it here)
  • A Maven project

NOTE: Sonatype Nexus can also be installed on Windows

Installation of Sonatype Nexus

Execute the following lines in your virtual machine:

Once you see the message Started Nexus OSS. you can browse your Nexus Installation at http://[Your Virtual Machine IP]:8081/nexus/index.html

This is how the Nexus site is displayed

Sonatype Nexus Home Screen

Check your Nexus Installation

Well, your nexus installation comes with some default proxies, let’s check them out, but first log in as admin, click at the top right “Log In” link as enter admin / admin123, this is the default user, you can change it later. Now click at Repositories

Some default repositories

As you can see, Nexus comes with some proxies that are already pointing to classic repositories like http://repo1.maven.org/maven2/, that means any maven project that you compile and requires something from that repository, nexus will pull from it and store it locally on your server. You can also have hosted repositories, these repositories are quite useful, you can upload some jars that you or your compile and publish them locally over your company network, or host those third-party dependencies that are not available in public maven repositories. This clearly helps a lot if you are trying to keep control of your artifact in a centralized way

Notice the tabs below:

Browse Local - Browse Remote, The big difference

Browse Remote allows you to check what artifacts are available online, while browse local displays just the ones that are already hosted in your server. Nexus downloads just what you need, so you can expect to see a few artifact when you browse locally

Now, configure your Maven Project

Take a look at classic pom.xml

This particular pom.xml says that in order to use this software we need, junit, selenium-java, operadriver, selenium-remote-driver and jsch, plus, you must download it from http://maven.apache.org. We need to call our nexus server instead of maven.apache.org, let’s modify this by adding the repositories tag based on our nexus server, it’s providing central too!

This is how the POM looks after the modification, notice that ip address may change

After modifying the pom, let’s do a mvn install directly from eclipse, here is the result

As you can see, every single dependency was requested directly to our nexus server, the server will pull the artifacts from maven repository and store it locally while serving your project at the same time. Additional mvn installs from another computer in your company will pull the artifacts from your local server instead of going to the internet, this saves a lot of internet bandwidth. Also you have to consider that the version needed in your maven project is the only one that will be pulled from the remote repository, if you request a greater or lesser revision, nexus will pull it from a remote server if able.

And finally, let’s check the nexus site, click at browse local on your central proxy

Artifacts that were stored locally

That’s it!. Now you have a functional Nexus server, if you want to know what else you can do with Sonatype Nexus, please take a look at the documentation available here


Follow me

Carlos Alberto Umanzor Arguedas

Web Developer at carlosumanzor.com
Web Developer, QA Engineer and Gamer Enthusiast, Developer of Linkcrawler and Father of a future computer ninja.
Follow me

Pin It on Pinterest

Share This
Optimization WordPress Plugins & Solutions by W3 EDGE