Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify credentials for custom maven private repo

Tags:

java

maven

I have used this article (https://gist.github.com/fernandezpablo85/03cf8b0cd2e7d8527063) for creating a custom maven repo, and it works. But now I have a problem with a private repo. How can I specify credentials for the private repo?

like image 639
Karen Avatar asked Nov 21 '25 17:11

Karen


2 Answers

You can set in .m2/settings.xml file

Like This:

<settings>
    <servers>
        <server>
            <id>private-repo</id>
            <username>xyz</username>
            <password>${pass}</password>
        </server>
    </servers>
</settings>

And in pom.xml:

<project>
    ...
    <repositories>
        <repository>
            <id>private-repo</id>
            <url>${private-repo.url}</url>
        </repository>
    </repositories>
    ...
</project>
like image 127
Ninad Pingale Avatar answered Nov 23 '25 06:11

Ninad Pingale


A settings.xml file is usually found in a couple of places:

  • Global settings in Mavens home directory: ${maven.home}/conf/settings.xml
  • User settings in the user’s home: ${user.home}/.m2/settings.xml

If both files exist, their contents are merged. Configurations from the user settings take precedence.

If your settings doesn't apply you can try to override the default settings.xml file location by adding --settings flag to your mvn ... command.

sources:

  • https://www.baeldung.com/maven-settings-xml#settings-level
  • https://www.baeldung.com/maven-settings-xml#3-override-the-default-location
like image 42
Denys Avatar answered Nov 23 '25 08:11

Denys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!