There are many people who use Apache Maven or Ant for years but do no use a repository manager like Nexus or Artifactory. Maybe initial step is something everyone need to overcome.This article describes how you can setup and get running your Nexus – an Artifact Repository Manager. Let’s begin with short motivation
Motivation
In my last article i introduced basic maven concepts, even when dependency management was not covered explicitly it is still one of the greatest thing maven introduced to the java eco-system. Most of maven builds produces artifacts also projects do depend on another artifacts (e.g java jar files) in different versions and configurations. It’s all about managing the artifacts. Therefore every maven installation already brings a repository that may be sufficient for single developer or small team. But the more professional your software development is the more reason is present professional artifact repository. Long story short the reasons are…
- More control (Releases, Dependencies, Audits)
- Predictability and Scalability
- Speeding up of Builds
- Saving Bandtwidth
- 3dt party artifact flexiblity
- Intra/inter organisational colaboration and distribution of work
If interested read more details.
Installation & Configuration
First of all it good practice to thing about low level things like, hardware, bandwidth, operating system and backup strategy… but i don’t cover it here. Following describes the installation of nexus on Debian Linux (Wheezy release). So let’s start…
One Pre Requirement is installed Java (JRE) 5 or higher.
# Start by creating new user and group, you will prompted do add additional info. adduser nexus #change to work dir cd /tmp #Then download fresh version of nexus. In my case v2.1.2 wget www.sonatype.org/downloads/nexus-2.1.2-bundle.tar.gz #Create nexis basedir and change to it mkdir /usr/lib/nexus-oss cd /usr/lib/nexus-oss/ #Extract nexus-2.1.2 omly directory from archive. No need of extracting working dir. tar xzvf /tmp/nexus-2.1.2-bundle.tar.gz nexus-2.1.2/ # Creating new symlink to avoit version in path. ln -s nexus-2.1.2/ nexus
Now basic’s are done. But do not start Nexus now…
I don’t wannt to create “big” artifact repository (or nexus’s working dir) in the same default place…
Also i’ wann’t to register the inid.d script to be able to control the nexus server an start it automatically. Last but not least i have to provide some configuration for example a “run as” Linux user for Nexus.
Let’s assume the repository should be in directory:
/srv/nexus/main-repo
then to the following:
mkdir /srv/nexus/main-repo #Set owner user and group chown nexus:nexus /srv/nexus/main-repo
Now open /usr/lib/nexus-oss/nexus-2.1.2/conf/nexus.properties file and change nexus-work property to:
nexus-work=/srv/nexus/main-repo
Now we are ready to register the provided init.d script that will allow us to run nexus as a Linux daemon.
# copy init.d sctipt to proper place cp /usr/lib/nexus-oss/nexus/bin/nexus /etc/init.d/nexus #replace default location sed -i "s/NEXUS_HOME=\"..\"/NEXUS_HOME=\"\/usr\/lib\/nexus-oss\/nexus\"/g" /etc/init.d/nexus #Set PID dir sed -i "s/#PIDDIR=\".\"/PIDDIR=\"\/var\/run\"/g" /etc/init.d/nexus #Set RUN_AS user to nexus sed -i "s/#RUN_AS_USER=/RUN_AS_USER=nexus/g" /etc/init.d/nexus #now register the new script update-rc.d nexus defaults
In case of troubles or for different Linux distributions look here
Congratulation! Now you’r Nexus installation is available on http://localhost:8081/nexus/. The default user and password are
“admin” and “admin123“.
Basic configuration of the maven clients
Login as admin, locate predefined repositories. All repositories of type “proxy” need to change “Download Remote Indexes” property to true in the configuration tab.
As you see there are several types of repositories.
- proxy - acts as proxy for external repository.
- hosted - repository that managed artifact produced by you
- virtual - kind of adapter for e.g transforming maven1 to maven 2 format.
- group - maybe not a repository in sonatyp’s terminology but behaves like one. A group groups several repositories to one exposing result as single URI.
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://YOR_NEXUS_HOST:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
Then we use a power of Maven Profiles and define new repositories they are magically (consider “*” in the mirror declaration) maps to the mirror.
<profile>
<id>nexus</id>
<!--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>
Do not forgete to activate thins new profile
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
Now your maven client knows only your nexus and everything it needs and how it gets it, should be controlled by nexus.
Look here for more client configuration details.
Further Reading & Comparison of Repositories
- Get fammilar with different repository types and options.
- Nexus vs. Nexus Pro
- Archiva vs. Artifactory vs. Nexus
- Artifactory vs. Nexus stackoverflow discussion
Thanks for this post!
Latest blog post: Audi importeren