简体   繁体   中英

can I use several usernames in maven settings.xml file?

our Nexus repository is configured to use repository-target permissions: user1 can deploy to com.company.group1, user2 can deploy to com.company.group2, etc.

can we have both user1 and user2 credentials for the same Maven repository in .m2/settings.xml file? will Maven try them both if permission is denied for one of them?

I use properties in distributionManagement, like-

  <distributionManagement>
    <repository>
      <id>releases</id>
      <url>${url.releases}</url>
    </repository>
    <snapshotRepository>
      <id>snapshots</id>
      <url>${url.snapshots}</url>
    </snapshotRepository>
    <site>
      <id>site</id>
      <url>${url.site}</url>
    </site>
  </distributionManagement>

My settings.xml has profiles that define these properties for target repositories. The <id> are matched with the <server> in the settings.xml, so you could use different <id> for different username/password/repository combination. In settings.xml, setup <activeProfiles> to the default profile you need for your deployment. When you need to switch to a different profile, you can do so on the command line.

You can't mix credentials in the same settings.xml file, as far as I know; seems this would be a large security hole. Each user should have his own login on your build machine; then each person has his own .m2/settings.xml and .m2/settings-security.xml files (you need the latter to encrypt passwords ). Each user adds <server> entries with ids matching the ids in the <distributionManagement> section for the projects being deployed.

You could eg use different profiles for each user and set user name and password as properties in those profiles. Then you could activate the profile depending on what user you want to work as at the moment. You could also set one of the profiles to be active by default so that you don't have to always use a profile name in your invocations.

Another way to do it would be to have separate settings.xml files for the users and specify the desired one with the -s flag for the maven invocation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM