How to pass Maven settings via environmental vars

后端 未结 3 1635
无人共我
无人共我 2020-12-29 23:18

In our setting.xml file we have the following:


    
      deploymentRepo
      repouser<         


        
相关标签:
3条回答
  • 2020-12-29 23:59

    You can pass the URL including the credentials like

    mvn deploy -DaltReleaseDeploymentRepository=myrepo::https://user:pass@server/repo

    see https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html

    0 讨论(0)
  • 2020-12-30 00:04

    Yes, you can do this in two ways:

    • passing properties in command line, using variables. For example, you can use in your settings.xml something like this:
    <servers>
        <server>
          <id>deploymentRepo</id>
          <username>${server.username}</username>
          <password>${server.password}</password>
        </server>
    </servers>
    

    And in command line, pass these variables in this way:

    mvn clean package -Dserver.username=yourusername -Dserver.password=yourpassword
    
    • exporting environments properties. For example, if you export (in 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 about propeties, see the reference documentation.

    0 讨论(0)
  • 2020-12-30 00:21

    You can pass values from 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 sure-fire plugin doc

    0 讨论(0)
提交回复
热议问题