views:

260

answers:

2

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...

+1  A: 

I don't know of a simple way to do this. But you can write a small plugin and bind it to an early phase, then access the settings values from within the plugin and either use them directly in your plugin, or expose them as properties.

You can see how to read values from the settings by looking at the source of the nexus-maven-plugin, and how to set them by looking at the properties-maven-plugin

Rich Seller
+2  A: 
Pascal Thivent
In general I agree, but there are use cases for accessing them within the build, as shown by the nexus-maven-plugin
Rich Seller