Introduction
Nexus is the best java artifact repository management software so far as I know. Enterprise software development shop should use repository management system to proxy the outside world repository and also to manage the life cycle of their internal software.This article will walk you through the fundamental process to install, start Nexus, and deploy an maven artifact to the Nexus repository. For the complete reference, you may take a look at this reference book. Personally, I don't like this kind of reference. Nowadays, who has the time to read through the whole books?
Download and Install Nexus OSS
- Go to this page to download the Nexus OSS
- Download nexus-2.11.0-02-bundle.tar.gz (this is the current version)
- cd ; mkdir nexus ; cd nexus
- tar xvzf ~/Downloads/nexus-2.11.0-02-bundle.tar.gz
1 2 | [/Users/Gary2013/nexus/nexus-2.11.0-02]$ ls LICENSE.txt NOTICE.txt bin conf lib logs nexus tmp |
1 2 | cd bin ./nexus start |
Configure Nexus OSS
By default, Nexus use http port 8081. You can open a browser and go to http://localhost:8081/nexus Once the default Nexus page is rendered, you can login in using the default admin:1 2 | username: admin password: admin123 |
1 2 | username: deployment password: deployment123 |
Configure Maven
In order to deploy java artifacts to Nexus Repository, we will need to update maven configuration file ~/.m2/setttings.xmls1 2 3 4 5 6 7 8 9 10 11 12 | <servers> <server> <id>deployment</id> <username>deployment</username> <password>deployment123</password> </server> <server> <id>gary</id> <username>gary</username> <password>gary1234</password> </server> </servers> |
Project Configuration To Use Local Nexus
After Nexus starts, we need to configure our project to be deployable to the Nexus repository. Here is all we need to do in our pom.xml file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <modelversion>4.0.0</modelversion> <groupid>com.ggl.fuse</groupid> <artifactid>fuse.message</artifactid> <version>0.0.2-SNAPSHOT</version> <distributionmanagement> <repository> <id>deployment</id> <url>http: //localhost:8081/nexus/content/repositories/releases</url> </repository> <snapshotrepository> <id>deployment</id> <url>http: //localhost:8081/nexus/content/repositories/snapshots</url> </snapshotrepository> </distributionmanagement> <build> <plugins> <plugin> <groupid>org.sonatype.plugins</groupid> <artifactid>nexus-staging-maven-plugin</artifactid> <version>1.6.3</version> <executions> <execution> <id> default -deploy</id> <phase>deploy</phase> <goals> <goal>deploy</goal> </goals> </execution> </executions> <configuration> <serverid>deployment</serverid> <nexusurl>http: //localhost:8081/nexus/</nexusurl> <!-- <stagingProfileId>1296f79efe04a4d0</stagingProfileId> --> <skipstaging> true </skipstaging> </configuration> </plugin> </plugins> </build> </project> |
If you look at the Nexus repository, you will find releases and snapshots as shown in the following figure:
The question is how does maven know into which repository the artifacts should be put? The answer is that in our version tag. If we put the version like:
1 | <version>0.0.2-SNAPSHOT</version> |
The maven will put the artifact into snapshots repository. If the version has no SNAPSHOT, the artifacts will be put into release repository
No comments:
Post a Comment