Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the values of server defined in the settings.xml to use them in my pom.xml?

I know I can retrieve some settings.xml parameters using properties, like, for example ${settings.localRepository} to get the location of the local repository.

Now imagine my settings.xml contains the following servers definition:

<servers>
    <server>
        <id>server-dev</id>
        <username>devuser</username>
        <password>devpass</password>
    </server>
    <server>
        <id>server-hom</id>
        <username>homuser</username>
        <password>hompass</password>
    </server>
</servers>

Is there a way, given an id of a server to get the value of any parameter? For example, something like ${settings.servers.server.server-dev.username} would return devuser.

I've already tried the following:

${settings.servers.server.server-dev.username}
${settings.servers.server-dev.username}
${settings.servers.server[server-dev].username}
${settings.servers[server-dev].username}

but none of them worked...


Regarding this page, this is not possible. However, as it is a feature not correctly documented, I still have some hope to do that in this way...

like image 925
Romain Linsolas Avatar asked Oct 13 '09 09:10

Romain Linsolas


People also ask

What is servers in Maven settings xml?

A Maven settings. xml file defines values that configure Maven execution in various ways. Most commonly, it is used to define a local repository location, alternate remote repository servers, and authentication information for private repositories.

Which of the build profile is defined in Maven settings xml file?

This build profile is defined in Maven global settings xml file i.e. at %M2_HOME%/conf/settings. xml location where Maven plugin is installed. The following are the number of ways to activate a Maven build profile. Use of command on the input console explicitly.


1 Answers

In case you are on Maven 3+, this can be achieved with servers-maven-extension. Once registered, settings.xml/servers content can be referenced using ${settings.servers.server.<server id>.<property>} (e.g. ${settings.servers.server.server-dev.username}).

disclosure: I am the maintainer of the project.

like image 52
Stanley Shyiko Avatar answered Sep 24 '22 20:09

Stanley Shyiko