Setting a single server credentials in Maven for multiple repositories

前端 未结 3 1530
太阳男子
太阳男子 2021-02-19 01:11

Can I have multiple repositories in Maven settings.xml with a single server credentials?

We\'re using Maven 3.0.4 to deploy artifacts to Nexus pro version 2.2.1

相关标签:
3条回答
  • 2021-02-19 01:17

    Yes, at least I believe this should work.

    Instead of

    <repository>
       <id>SNAPSHOTS</id>
       <url>http://server/nexus/content/repositories/SNAPSHOTS</url>
    </repository>
    

    Use

    <repository>
      <id>nexus</id>
      <name>SNAPSHOTS</name>
      <url>http://server/nexus/content/repositories/SNAPSHOTS</url>
    </repository>
    

    Then just reference nexus as your server id.

    0 讨论(0)
  • 2021-02-19 01:27

    Seems I'm not allowed to comment because I'm not experienced enough. As if :) However, regarding the WARNING profiles.profile[development].repositories.repository.id must be unique, I found this to be two settings.xml files being found. One in a maven installation's ${maven-install}/conf/settings.xml as well as a one in ~/.m2/settings.xml. Decide which one you want and clean up the other.

    0 讨论(0)
  • 2021-02-19 01:43

    Because each repository definition should have unique id - and id must be connected with server section so it is not way to have one server for many repositories.

    Trying put username and password in properties also have no expected result because properties in defined in setting.xml are not resolved in the same settings.xml

    But we can define environment variables with user name and password and use it in settings.xml

    So we can have in settings.xml:

    <server>
       <id>Staging-group</id>
       <username>${env.MVN_USER}</username>
       <password>${env.MVN_PASS}</password>
    </server>
    <server>
       <id>RELEASES</id>
       <username>${env.MVN_USER}</username>
       <password>${env.MVN_PASS}</password>
    </server>
    <server>
       <id>SNAPSHOTS</id>
       <username>${env.MVN_USER}</username>
       <password>${env.MVN_PASS}</password>
    </server>
    

    Now we must define somewhere used environment variables, we can use for it ~/.mavenrc so this variables will be available only for maven.

    example of ~/.mavenrc

    export MVN_USER=user
    export MVN_PASS=pass
    

    This workaround give us possibility to have defined username and password for many repositories in one place.

    Testing with maven 3.6.3

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