Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: How to use properties from settings.xml via settings. prefix?

Tags:

maven

When I add settings to settings.xml in this way...

  <profiles>
    <profile>
        <id>outsorced-project-properties</id>
        <properties>
            <key.password>mysecretpassword</key.password>
        </properties>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>outsorced-project-properties</activeProfile>
  </activeProfiles>

..then I can use ${key.password} with my project's pom.xml. This works but seems to be a little bit inconvenient.

In MavenPropertiesGuide thers is an information that you can use settings from settings.xml via settings. prefix.

Local user settings

Similarly, values in the user's settings.xml can be referenced using property names with settings. prefix.

${settings.localRepository} refers to the path of the user's local repository

But this doesn't seem to work for me. At least I don't know how to define them within settings.xml. I tried to define them just within settings tag of settings.xml, or within a properties tag within the settings tags and so on, but the properties were never recognized. Did I understand anything wrong?

like image 651
Bevor Avatar asked Oct 29 '25 12:10

Bevor


1 Answers

I don't think you can differentiate between the properties based on where they are defined. (i.e ${settings.key.password} or ${settings.properties.key.password} won't give you your password)

but if you are after the settings prefix, you can add the below to your settings file

<properties>
  <settings.password>mypassword</settings.password>
</properties>

and then refer it as ${settings.password} in your pom files.

like image 163
coderplus Avatar answered Oct 31 '25 09:10

coderplus



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!