Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven distributionManagement or Server (User and Password) as parameter

Tags:

maven

nexus

I have a remote repository using Nexus.

These Repositories asks for login, I would prefer to expose these repositories with login.

This is my settings.xml

<settings>

<servers>
    <server>
        <id>dev-repo</id>
        <username>user</username>
        <password>password</password>
    </server>
</servers>

</settings>

And the developers are using a pom.xml with:

<distributionManagement>
            <repository>
                <id>dev-repo</id>
                <url>http://ip:port/nexus/content/repositories/dev-repo/</url>                          
            </repository>
    </distributionManagement>

With that configuration everything is OK, but I prefer they have to pass the login in the mvn command or the command ask with a prompt the login instead hard code the login in settings.xml

Any ideas?

Thank you in advance.

like image 328
Daniel Hernández Avatar asked Aug 17 '15 18:08

Daniel Hernández


People also ask

What is the use of distributionManagement in Maven?

Maven - Distribution Management xml section is responsible to define: the remote repositories. how to deploy the project's site and documentation.

What is distributionManagement tag in Maven?

From the POM reference: Where as the repositories element specifies in the POM the location and manner in which Maven may download remote artifacts for use by the current project, distributionManagement specifies where (and how) this project will get to a remote repository when it is deployed.

What is snapshotRepository?

snapshotRepository. Repository contains the information needed for deploying to the remote repository. Element.


1 Answers

It's quite easy: The settings.xml file allows variables. Replace user and password by named variables:

<servers>
    <server>
        <id>dev-repo</id>
        <username>${user}</username>
        <password>${password}</password>
    </server>
</servers>

And then, provide explicit values when invoking to Maven:

mvn -Duser=... -Dpassword=... install
like image 135
Little Santi Avatar answered Oct 09 '22 19:10

Little Santi