Powered By Blogger

Mar 5, 2015

Maven private remote repository setup


1. Download nexus-2.11.1-01-bundle.tar.gz or latest version of nexus oss.

2. Extract the tar file in you home directory-

$ tar -xvf nexus-2.11.1-01-bundle.tar.gz
Now you will get two directories - nexus-2.11.1-01 and sonatype-work in your home directory.

3. Copy these two directories to /usr/local/ directory 

$ cp -r nexus-2.11.1-01 /usr/local/
$ cp -r sonatype-work /usr/local/

The executable/configuration files related to nexus are stored in nexus-2.11.1-01 directory and the jar file mentioned in pom.xml are stored in sonatype-work directory.

These jar files are mirror of your ~/.m2/repository. First time you issue a mvn package command then all the jars are stored here. After then when you issue mvn package again then all jars are downloaded from the nexus repository instead of downloading from the central repository.

4. Go to the /usr/local/ directory 

$ cd /usr/local/  

5. Create a link to nexus-2.11.1-01 

$ sudo ln -s nexus-2.7.0-06 nexus

6. Now to run nexus, execute the following 

$ bash nexus/bin/nexus console  

Here nexus is attached with your console. If you close your console then the nexus server will be terminated. 

7.Then grant permission as follows

$ sudo chmod -R 777 nexus-2.11.1-01/
$ sudo chmod -R 777 sonatype-work/

8. Now in browser type the address - http://localhost:8081/nexus/. The default login user name is - admin and password is - admin123

9. To stop nexus. Just close the terminal or press Ctrl+C. Copy the following content into this settings.xml file 

<settings>
    <mirrors>
        <mirror>
        <!--This sends everything else to /public -->
            <id>nexus</id>
            <mirrorOf>*</mirrorOf>
            <url>http://localhost:8081/nexus/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>
    </profiles>

    <activeProfiles>
    <!--make the profile active all the time -->
        <activeProfile>nexus</activeProfile>
    </activeProfiles>
</settings>

10. And add these following line in your project's pom.xml file 

<distributionManagement>
    <snapshotRepository>
        <id>my-snapshots</id>
        <name>My internal repository</name>
        <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
    </snapshotRepository>

    <repository>
        <id>my-releases</id>
        <name>My internal repository</name>
        <url>http://localhost:8081/nexus/content/repositories/releases</url>
    </repository>
</distributionManagement>

No comments:

Post a Comment