Getting started with Nexus Maven Repo Manager
Join the DZone community and get the full member experience.
Join For FreeThis tutorial outlines steps required to install Nexus (Maven Repository Manager) under Tomcat, or another webapp container. It shows you practical configuration and includes code snippets that go in your pom.xml and settings.xml in order to read and publish artifacts to your Nexus server.
Step 1: Download
Download Nexus from here (at the time of writing, latest is 1.6.0)
Step 2: Install
Copy the war to TOMCAT_HOME/webapps/nexus.war
Though not required, it is a generally good idea to restart tomcat after installing a new war
/etc/init.d/tomcat restart
Step 3: Configure security
a) Change default admin password: The default admin username/password is admin/admin123. Login as admin and change the password to a secure password.
Login -> [admin, admin123] -> Left Menu -> Security -> Change Password -> click “Change Password”
b) Anonymous Access: By default Nexus is open to the public. If you want to secure access to nexus, disable ‘Nexus anonymous user’
Admin -> Left Menu -> Users -> ‘Nexus anonymous user’ -> Status=Disabled
c) Deployment user: Change password for deployment user
Admin -> Left menu -> Users -> Deployment user -> Change email address
Admin -> Left menu -> Users -> Right click on ‘Deployment user’ in the user list -> Set Password -> click ‘Set password’ to finish
Step 4: Set SMTP server
It is a good idea to configure SMTP server, so that you can receive emails from Nexus.
Admin login -> Left menu -> Administration -> Server ->SMTP Settings -> (host localhost, port 25, no login, no password mostly works on a linux machine)
Step 5: Change Base Url
If you are running Nexus behind Apache using mod_jk or mod_proxy, change your base url here.
Admin login -> Left menu -> Administration -> Server -> Application Server Settings -> Base url
Step 6: Add a task to periodically remove old snapshots
If you or your CI server publishes snapshots to Nexus several times a day, then you should consider adding a task to delete duplicate/old snapshots for the same GAV (group, artifact, version). If you don’t do this, you will notice that the Nexus disk usage will increase with time.
Admin login -> Left menu -> Administration -> Scheduled tasks -> Add… -> name=”Remove old snapshots”, Repository/Group=Snapshots (Repo), Minimum Snapshot Count=1, Snapshot Retention(days)=3, Recurrence=Daily, Recurring time=2:00 -> click ‘Save’
Step 7: Using Nexus: reading and publishing artifacts
If you want to deploy your artifacts to your Nexus, you need to configure 2 files: pom.xml and settings.xml
a) pom.xml – for each project which wishes to publish to Nexus, add your repo to the pom.xml
<distributionManagement>
<!-- Publish the versioned releases here -->
<repository>
<id>vineetmanohar-nexus</id>
<name>vineetmanohar nexus</name>
<url>dav:http://nexus.vineetmanohar.com/nexus/content/repositories/releases</url>
</repository>
<!-- Publish the versioned releases here -->
<snapshotRepository>
<id>vineetmanohar-nexus</id>
<name>vineetmanohar nexus</name>
<url>dav:http://nexus.vineetmanohar.com/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<!-- download artifacts from this repo -->
<repositories>
<repository>
<id>vineetmanohar-nexus</id>
<name>vineetmanohar</name>
<url>http://nexus.vineetmanohar.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- download plugins from this repo -->
<pluginRepositories>
<pluginRepository>
<id>vineetmanohar-nexus</id>
<name>vineetmanohar</name>
<url>http://nexus.vineetmanohar.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
b) settings.xml – If you have disabled anonymous access to Nexus, add the deployment password to your ~/.m2/repository/settings.xml file
<settings>
<servers>
<server>
<!-- this id should match the id of the repo server in pom.xml -->
<id>vineetmanohar-nexus</id>
<username>deployment</username>
<password>password_goes_here</password>
</server>
</servers>
</settings>
From http://www.vineetmanohar.com/2010/06/getting-started-with-nexus-maven-repo-manager
Opinions expressed by DZone contributors are their own.
Comments