Skip to content

Added support for configuring multiple maven repositories with separate usernames and passwords#827

Closed
sudiptosarkar wants to merge 1 commit into
actions:mainfrom
sudiptosarkar:features/multiMavenRepoConfig
Closed

Added support for configuring multiple maven repositories with separate usernames and passwords#827
sudiptosarkar wants to merge 1 commit into
actions:mainfrom
sudiptosarkar:features/multiMavenRepoConfig

Conversation

@sudiptosarkar

@sudiptosarkar sudiptosarkar commented May 12, 2025

Copy link
Copy Markdown

Description:
This PR adds support for configuring multiple maven repositories with separate usernames and passwords for each. Currently the action only supports one repository configuration, which makes it impossible to specify more than one (release and snapshot repositories for example). That would inevitably lead to changing the maven config in the action yaml every time the version changes to/from release/snapshot.

Related issue:
#828

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

@sudiptosarkar sudiptosarkar requested a review from a team as a code owner May 12, 2025 19:55
@sudiptosarkar sudiptosarkar force-pushed the features/multiMavenRepoConfig branch 2 times, most recently from 8c10b2a to bfbdaa6 Compare May 12, 2025 20:33
@brunoborges

Copy link
Copy Markdown
Contributor

Linking this PR to the tracked issue: #828 (Need support for multiple maven repositories).

Copilot AI review requested due to automatic review settings June 22, 2026 16:51
@brunoborges brunoborges force-pushed the features/multiMavenRepoConfig branch from bfbdaa6 to 0b51851 Compare June 22, 2026 16:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the Maven authentication/settings.xml generation in actions/setup-java to support configuring multiple Maven <server> entries (intended for scenarios like separate release/snapshot repositories), and updates documentation and CI to demonstrate/validate the behavior.

Changes:

  • Introduces a MvnSettingDefinition model and updates settings.xml generation to emit multiple <server> entries.
  • Adds a new input (mvn-repositories-len) and indexed server inputs in the action metadata and documentation.
  • Updates unit tests and the e2e publishing workflow to exercise multi-repo settings generation.
Show a summary per file
File Description
src/mvn.setting.definition.ts Adds a typed definition for Maven server/GPG setting entries.
src/constants.ts Adds a new input constant for mvn-repositories-len.
src/auth.ts Refactors settings.xml generation to support multiple server entries and indexed inputs.
__tests__/auth.test.ts Updates tests for new generate(mvnSettings) signature and adds a multi-repo settings.xml test.
action.yml Adds new inputs for multi-repo configuration (currently only indexes 0 and 1).
docs/advanced-usage.md Documents multi-repo Maven configuration and provides an example settings.xml output.
.github/workflows/e2e-publishing.yml Adds an e2e job intended to validate multi-repo settings.xml output.
dist/setup/index.js Updates compiled distribution bundle for the new auth logic/constants.
dist/cleanup/index.js Updates compiled distribution bundle exports for the new input constant.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 7/9 changed files
  • Comments generated: 9

Comment thread src/auth.ts
Comment on lines +24 to +28
let gpgPrivateKey;
if (numMvnRepos === '' || core.getInput(constants.INPUT_GPG_PRIVATE_KEY)) {
gpgPrivateKey = populateMvnSettings(mvnSettings);
} else {
for (let i = 0; i < parseInt(numMvnRepos); i++) {
Comment thread src/auth.ts
Comment on lines +57 to +59
if (username !== '' && password !== '') {
mvnSettings.push({id: id, username: username, password: password});
}
Comment thread __tests__/auth.test.ts
Comment on lines 87 to 91
await auth.createAuthenticationSettings(
id,
username,
password,
[{id, username, password, gpgPassphrase}],
m2Dir,
true,
gpgPassphrase
true
);
Comment on lines +189 to +191
if (($servers[1].id -ne 'maven-1') -or ($servers[0].username -ne '${env.MAVEN_PASSWORD-1}') -or ($servers[1].password -ne '${env.MAVEN_CENTRAL_TOKEN-1}')) {
throw "Generated XML file is incorrect"
}
Comment on lines +193 to +195
if (($servers[1].id -ne 'gpg.passphrase') -or ($servers[1].passphrase -ne '${env.MAVEN_GPG_PASSPHRASE}')) {
throw "Generated XML file is incorrect"
}
Comment thread docs/advanced-usage.md
Comment on lines +457 to +462
env:
ARTIFACTORY_USERNAME: maven_username123
ARTIFACTORY_TOKEN: ${{ secrets.ARTIFACTORY_USERNAME }}
SNAPSHOT_ARTIFACTORY_USERNAME: snapshot_maven_username123
SNAPSHOT_ARTIFACTORY_TOKEN: ${{ secrets.SNAPSHOT_ARTIFACTORY_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
Comment thread docs/advanced-usage.md
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
```

Here `mvn-repositories-len` specifies how many artifactories we're configuring here. In this example, the value is 2. In this case, the action will look for `server-id-0`, `server-username-0`, `server-password-0`, `server-id-1`, `server-username-1` and `server-password-1`.
Comment thread action.yml
Comment on lines +44 to +46
mvn-repositories-len:
description: 'Number of Maven repositories being configured - Only applicable if more than one Maven repository is being configured'
required: false
Comment thread src/auth.ts
Comment on lines +15 to 19
const numMvnRepos = core.getInput(constants.INPUT_NUM_MVN_REPOS);
const mvnSettings: Array<MvnSettingDefinition> = [];
const settingsDirectory =
core.getInput(constants.INPUT_SETTINGS_PATH) ||
path.join(os.homedir(), constants.M2_DIR);
@brunoborges

Copy link
Copy Markdown
Contributor

Maintainer design follow-up: I implemented an alternative in #1037 with a tighter surface area.

Why this design: #827 introduces indexed input tuples (for example server-id-0/server-username-0/server-password-0), which scale poorly and increase maintenance and docs complexity as the number of repositories grows.

What #1037 does differently:

  • adds a single structured multiline input: mvn-server-credentials
  • one line per server in the format: server-id:USERNAME_ENV:PASSWORD_ENV
  • keeps full backward compatibility by preserving the existing single-server inputs as fallback
  • includes explicit validation for malformed entries and duplicate server IDs

Net effect: same multi-repository capability with less API complexity and clearer long-term maintainability.

@brunoborges brunoborges added feature request New feature or request to improve the current logic maven Maven settings, toolchains, and publishing auth labels Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request New feature or request to improve the current logic maven Maven settings, toolchains, and publishing auth

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants