Skip to content

Support Maven mirrors in generated settings.xml #1287

Open

Description

@MelleD

Description

Add a new input mvn-mirrors to the Maven settings generation, analogous to mvn-repositories and mvn-plugin-repositories.

  • Format: multiline list of mirror-id:mirror-url:mirror-of.
  • mirror-of is the Maven <mirrorOf> pattern, e.g. *, central or external:*.
  • Each entry is written as a <mirror> into the <mirrors> section of the generated settings.xml.
  • Mirror IDs should match mvn-server-credentials IDs for authentication, as with mvn-repositories.

Example:

- uses: actions/setup-java@v6
  with:
    distribution: temurin
    java-version: '21'
    mvn-server-credentials: |
      private:PRIVATE_REPOSITORY_USERNAME:PRIVATE_REPOSITORY_TOKEN
    mvn-repositories: |
      private:https://maven.example.com/releases:false
    mvn-plugin-repositories: |
      private:https://maven.example.com/releases:false
    mvn-repositories-include-central: false
    mvn-mirrors: |
      private:https://maven.example.com/releases:*

Generated output:

<mirrors>
  <mirror>
    <id>private</id>
    <url>https://maven.example.com/releases</url>
    <mirrorOf>*</mirrorOf>
  </mirror>
</mirrors>

Justification

mvn-repositories and mvn-plugin-repositories only generate <repositories> and <pluginRepositories> in a profile. These are added on top of the repositories already declared elsewhere. Maven therefore still contacts:

  • Maven Central from the Super POM.
  • Any repository declared in a project or parent POM.

Even with mvn-repositories-include-central: false, these remain active. Builds in corporate environments, where all artifacts must come from an internal repository, can still reach external hosts or fail on them.

Only a <mirror> with <mirrorOf>*</mirrorOf> reliably redirects every repository, including central and POM-declared ones, to the internal repository. The action cannot configure this today.

The current workaround is a custom step that patches ~/.m2/settings.xml after setup-java has run, for example:

perl -0pi -e 's#<servers>#<mirrors>...</mirrors><servers>#' ~/.m2/settings.xml

The other option is a hand-written settings.xml with overwrite-settings: false. Both defeat the purpose of the mvn-repositories and mvn-server-credentials inputs. A native mvn-mirrors input removes the need for this patching.

Activity

  1. v-priyagupta108 commented on Oct 16, 2026

    @v-priyagupta108
    Contributor

    Hello @MelleD,
    Thank you for reporting this issue. We will investigate it and get back to you as soon as we have some feedback.

  2. brunoborges commented on Oct 16, 2026

    @brunoborges
    Contributor

    @MelleD, the implementation is available in #1289 and the same commit is now published directly in actions/setup-java. Could you test it with your internal Maven repository by pinning your setup-java step to this exact commit?

    - uses: actions/setup-java@db92f3d58c2f05dc3b4dfc6c2b2b258feb331686
      with:
        distribution: temurin
        java-version: '21'
        mvn-server-credentials: |
          private:PRIVATE_REPOSITORY_USERNAME:PRIVATE_REPOSITORY_TOKEN
        mvn-mirrors: |
          private:https://maven.example.com/releases:*

    Replace the example mirror URL with your internal repository URL and keep your existing credential environment variables available to the Maven build step. You can retain your existing repository inputs; mvn-mirrors also works without them.

    Please let us know whether dependency and plugin resolution now goes through your internal mirror, including Central and repositories declared in project/parent POMs, without the manual settings.xml patch.

  3. self-assigned this
    on Oct 16, 2026
  4. MelleD commented on Oct 19, 2026

    @MelleD
    Author

    @brunoborges thanks works as expected :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feature requestNew feature or request to improve the current logic

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions