Search code examples
javamavenmaven-3nexusnexus3

Integrate maven with nexus repository


I have installed nexus repository 3.12 in a server machine and apache-maven 3.3.9 in my local computer.

I want to configure maven to access repository. I created a repository in nexus as maven_ub and edit the settings.xml file as below.

File path : C:\Program Files\apache-maven-3.3.9\conf\settings.xml

<mirrors>
   <mirror>
     <id>Nexus</id>
     <mirrorOf>central</mirrorOf>
     <name>Nexus Public Mirror</name>
     <url>http://1.2.3.4:8081/repository/maven_ub/</url>
   </mirror>
</mirrors>

But still when i build the project with dependencies it gets the dependencies through the maven central repository.

Is any one can explain how to fix this issue.Thanks in advance.


Solution

  • As far as I know, you must add a custom repository to the desired pom.xml. Then, authentication credentials must be set up in your $HOME/.m2/settings.xml that way:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
        <servers>
            <server>
                <id>myRepo</id>
                <username>myUser</username>
                <password>myPass</password>
                <filePermissions>AuthenticatedRead</filePermissions>
            </server>
        </servers>
        <!-- further config -->
    </settings>
    

    You can read more in here.