Technology Encyclopedia Home >How to configure private server account and password in Maven repository?

How to configure private server account and password in Maven repository?

To configure a private server account and password in a Maven repository, you need to modify the settings.xml file (located in the Maven conf directory or your user's .m2 folder) and add the server credentials under the <servers> section.

Steps:

  1. Open settings.xml (e.g., ~/.m2/settings.xml or %USERPROFILE%\.m2\settings.xml).
  2. Add a <server> entry with the repository ID (must match the ID in your pom.xml or settings.xml distribution management).
  3. Specify the username and password for authentication.

Example Configuration:

<settings>
    <servers>
        <server>
            <id>my-private-repo</id> <!-- Must match the repository ID in pom.xml -->
            <username>your-username</username>
            <password>your-password</password>
        </server>
    </servers>
</settings>

If your password is sensitive, you can encrypt it using Maven's password encryption feature:

  1. Run mvn --encrypt-password and enter your password.
  2. Replace the plain-text password with the encrypted one in settings.xml.

For Private Repositories (e.g., Tencent Cloud Container Registry):

If you're using a private registry like Tencent Cloud Container Registry (TCR), ensure:

  • The repository ID in pom.xml or distributionManagement matches the <server> ID.
  • The registry URL is correctly specified in pom.xml.

Example pom.xml snippet for Tencent Cloud TCR:

<distributionManagement>
    <repository>
        <id>my-private-repo</id> <!-- Matches settings.xml server ID -->
        <url>https://<tencent-tcr-endpoint>/repository/<repo-path>/</url>
    </repository>
</distributionManagement>

For secure credential management, consider using Tencent Cloud CAM (Cloud Access Management) roles or environment variables instead of hardcoding passwords.