Thursday 7 April 2016

Nexus Repository and its setup:

After installing java and maven, need to setup the maven local repository according to nexus repository urls:

Here are the steps to install nexus and setup with maven:

Installation of Nexus with the help of Docker:

Install the docker on Centos:
---------------------------------------
sudo yum update
sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
sudo yum install docker-engine
sudo service docker start

git clone the below repository from the github:
https://hub.docker.com/r/sonatype/nexus/

sonatype/docker-nexus

Docker images for Sonatype Nexus with the Oracle JDK.
To run (if port 8081 is open on your host):
# docker run -d -p 8081:8081 --name nexus sonatype/nexus:oss
To build:
# docker build --rm --tag sonatype/nexus oss/
# docker build --rm --tag sonatype/nexus-pro pro/
To determine the port that the container is listening on:
# docker ps nexus
To test:
$ curl http://localhost:8081/service/local/status
To build:
Copy the Dockerfile and do the build-
$ docker build --rm=true --tag=sonatype/nexus .

Notes

  • Default credentials are: admin / admin123
  • It can take some time (2-3 minutes) for the service to launch in a
    new container. You can tail the log to determine once Nexus is ready:
$ docker logs -f nexus
  • Installation of Nexus is to /opt/sonatype/nexus. Notably:
    /opt/sonatype/nexus/conf/nexus.properties is the properties file.
    Parameters (nexus-work and nexus-webapp-context-path) definied
    here are overridden in the JVM invocation.
Once it is done, check the below url whether it is working or not?
http://localhost:8081/service/local/status
if not change the localhost to ipaddress.

Once it is done, you are ready to open the nexus repository manager in your browser

Now, set the seetings.xml and pom.xml which are there in your maven local repository and path:

Here is the settingx.xml
<settings>
  <localRepository>{Local Repository]</localRepository>
  <servers>
<!-- This is the username password used to access my nexus repository -->
    <server>
       <id>releases</id>
       <username>deployment</username>
       <password>deployment123</password> <!-- impossible password here :-) -->
     </server>
    <server>
       <id>snapshots</id>
       <username>deployment</username>
       <password>deployment123</password> <!-- impossible password here :-) -->
     </server>
    <server>
       <id>nexus</id>
       <username>deployment</username>
       <password>deployment123</password> <!-- impossible password here :-) -->
     </server>
  </servers>

  <mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
<!--      <url>http://nexus.yourdomain.nl/content/groups/public</url> -->
     <url>http://ipaddress:8081/content/groups/public</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--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>
    <!-- if you want to be able to switch to the defaultprofile profile put this in the active profile -->
    <profile>
        <id>defaultprofile</id>
        <repositories>
            <repository>
                <id>maven.default</id>
                <name>default maven repository</name>
                <url>http://repo1.maven.org/maven2</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>maven.snapshot</id>
                <name>Maven snapshot repository</name>
                <url>http://people.apache.org/repo/m2-snapshot-repository</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories> 
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

pom.xml shuould be:
-------------------
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>my-app</name>
  <url>http://maven.apache.org</url>
<distributionManagement>
        <repository>
            <id>releases</id>
            <name>Releases</name>
            <url>http://ipaddress:8081/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Snapshots</name>
           <url>http://ipaddress:8081/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>
 <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

now execute mvn deploy command, you will see all the artifacts in Nexus Repository.

No comments:

Post a Comment