08 - Nexus Running Notes
08 - Nexus Running Notes
Sonatype Nexus
##################
-> Github is a SCM software which is used to store source code of the project
-> Nexus is Artifact Repository which is used to store build artifacts (jar / war)
##################
Nexus Setup
##################
$ sudo su -
$ cd /opt
Links to download :
https://help.sonatype.com/repomanager3/product-information/download
# latest version
$ wget https://download.sonatype.com/nexus/3/nexus-3.40.1-01-unix.tar.gz
$ mv /opt/nexus-3.40.1-01 /opt/nexus
#As a good security practice, Nexus is not advised to run nexus service as a root
user, so create a new user called nexus and grant sudo access to manage nexus
services as follows.
$ useradd nexus
# Add below line in suderos file (just below root user details we can add it)
nexus ALL=(ALL) NOPASSWD: ALL
$ vi /opt/nexus/bin/nexus.rc
run_as_user="nexus"
$ ln -s /opt/nexus/bin/nexus /etc/init.d/nexus
$ su - nexus
URL : http://IPAddess:8081/
# Default Username
User Name: admin
# we can copy nexus password using below command
$ sudo cat /opt/sonatype-work/nexus3/admin.password
/opt/nexus/etc/nexus-default.properties
#################################
Integrate Maven App with Nexus
#################################
1) snapshot
2) release
-> If project is under development then that project build artifacts will be stored
into snapshot repository
-> If project development completed and released to production then that project
build artifacts will be stored to release repository
Note: Based on <version/> name available in project pom.xml file it will decide
artifacts should be stored to which repository
-> Nexus Repository details we will configure in project pom.xml file like below
<distributionManagement>
<repository>
<id>nexus</id>
<name>Ashok IT Releases Nexus Repo</name>
<url>http://15.206.128.43:8081/repository/ashokit-release/</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Ashok IT Snapshots Nexus Repo</name>
<url>http://15.206.128.43:8081/repository/ashokit-snapshot/</url>
</snapshotRepository>
</distributionManagement>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin</password>
</server>
-> Once these details are configured then we can run below maven goal to upload
build artifacts to Nexus Server
Note: When we execute maven deploy goal, internally it will execute 'compile + test
+ package + install + deploy' goals.
##################
Remote Repository
##################
-> Remote repository used for shared libraries (common jars required for multiple
projects)
-> If we want to use few jar files in multiple projects in the company then we will
use Remote Repository to store those jars (libraries).
-> Go to Repositories
-> Create New Repository
-> Choose Maven (Hosted) Repository
-> Give a name for Repository (Ex: ashokit-remote-repository) & Complete the
process
-> Go to BrowseSection
-> Select Remote Repository (By default it is empty)
-> Click on Upload Component
-> Upload Jar file and give groupId, artifactId and Version
groupId : in.ashokit
artifactId : pwd-utils
version : 1.0
-> Take dependency details of uploaded jar file and add in project pom.xml as a
dependency like below
<dependency>
<groupId>in.ashokit</groupId>
<artifactId>pwd-utils</artifactId>
<version>1.0</version>
</dependency>
-> We need to add Remote Repository Details in pom.xml above <dependencies/> tag
<repositories>
<repository>
<id>nexus</id>
<url>http://15.206.128.43:8081/repository/ashokit-remote-
repo/</url>
</repository>
</repositories>
-> After adding the remote repository details in pom.xml then execute maven package
goal and see dependency is downloading from nexus repo or not.
=========================================
How to resolve HTTP Mirror Block Issue ?
=========================================
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>dummy</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using
HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>false</blocked>
</mirror>
===============
Nexus Summary
===============