How to get Maven settings through environmental vars

In our settings.xml file, we have the following:

<servers>
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
</servers>

      

Can these settings (or their equivalent) be passed through environment variables instead of settings.xml?

+3


source to share


2 answers


Yes, you can do it in two ways:

  • passing properties on the command line using variables. For example, you can use settings.xml

    something like this in yours :
<servers>
    <server>
      <id>deploymentRepo</id>
      <username>${server.username}</username>
      <password>${server.password}</password>
    </server>
</servers>

      

And on the command line, pass these variables like this:



mvn clean package -Dserver.username=yourusername -Dserver.password=yourpassword

      

  • export of environment properties. For example, if you are exporting (on linux, something like export SERVER_USERNAME=yourusername

    ) SERVER_USERNAME

    and SERVER_PASSWORD

    variables, you can use like this:
<servers>
    <server>
      <id>deploymentRepo</id>
      <username>${env.SERVER_USERNAME}</username>
      <password>${env.SERVER_PASSWORD}</password>
    </server>
</servers>

      

For more information on the offerings, see the documentation.

+8


source


You can pass values ​​from the command line

mvn -Dvar = someValue -Dtest.username = xyz install



In the POM file, you can refer to system variables (specified on the command line or in the pom) as $ {var} and environment variables as $ {env.myVariable}, i.e. $ {test.username}

You can also refer to the safe fire plan doc

0


source







All Articles