Skip to content

[MNG-6397] Maven Transitive Dependency Resolution Does Not Respect Repository Definition in pom.xml #7459

Open

Description

@jira-importer

Alan Czajkowski opened MNG-6397 and commented

Note: I am trying to do a build behind a firewall which means I cannot access the Internet, I can only access my internal Maven repository inside my network, so:

Let's begin:

My pom.xml has the following:

...
    <dependencies>
...
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>
...
    </dependencies>
...
    <repositories>
...
        <repository>
            <id>central</id>
            <name>Public</name>
            <url>https://artifacts.example.com/repository/maven/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
...
    </repositories>
...

The dependency:tree for the spring-boot-starter-web is as follows:

+- org.springframework.boot:spring-boot-starter-web:jar:2.0.0.RELEASE:compile
|  +- org.springframework.boot:spring-boot-starter-json:jar:2.0.0.RELEASE:compile
|  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.4:compile
|  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.4:compile
|  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.4:compile
|  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.0.0.RELEASE:compile
|  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.28:compile
|  +- org.hibernate.validator:hibernate-validator:jar:6.0.7.Final:compile
|  |  +- javax.validation:validation-api:jar:2.0.1.Final:compile
|  |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
|  |  \- com.fasterxml:classmate:jar:1.3.1:compile
|  \- org.springframework:spring-web:jar:5.0.4.RELEASE:compile

How is it that the build fails as such:

...
Downloading: https://repo.spring.io/milestone/org/jboss/shrinkwrap/shrinkwrap-bom/1.2.3/shrinkwrap-bom-1.2.3.pom
Downloading: https://repo.spring.io/snapshot/org/jboss/shrinkwrap/shrinkwrap-bom/1.2.3/shrinkwrap-bom-1.2.3.pom
Downloading: https://dl.bintray.com/rabbitmq/maven-milestones/org/jboss/shrinkwrap/shrinkwrap-bom/1.2.3/shrinkwrap-bom-1.2.3.pom
Downloading: https://repo.maven.apache.org/maven2/org/jboss/shrinkwrap/shrinkwrap-bom/1.2.3/shrinkwrap-bom-1.2.3.pom
...
[ERROR] Failed to execute goal on project maven-multi-module-demo-backend: Could not resolve dependencies for project com.example.pipe:maven-multi-module-demo-backend:war:1.0.0-SNAPSHOT: Failed to collect dependencies at org.springframework.boot:spring-boot-starter-web:jar:2.0.0.RELEASE -> org.hibernate.validator:hibernate-validator:jar:6.0.7.Final: Failed to read artifact descriptor for org.hibernate.validator:hibernate-validator:jar:6.0.7.Final: Could not transfer artifact org.jboss.shrinkwrap:shrinkwrap-bom:pom:1.2.3 from/to spring-milestone (https://repo.spring.io/milestone): Connection reset -> [Help 1]
...

when I did not even reference this repo spring-milestone ([https://repo.spring.io/milestone]) anywhere in my pom.xml?

When you go down the Spring Boot rabbit hole (go into the spring-boot-starter-web's pom.xml and then traverse up its parent-pom structure a few jumps) you'll eventually get to a parent-pom spring-boot-dependencies with this definition:

...
    <repositories>
        <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>spring-milestone</id>
            <name>Spring Milestone</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
        <repository>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <id>spring-snapshot</id>
            <name>Spring Snapshot</name>
            <url>https://repo.spring.io/snapshot</url>
        </repository>
        <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>rabbit-milestone</id>
            <name>Rabbit Milestone</name>
            <url>https://dl.bintray.com/rabbitmq/maven-milestones</url>
        </repository>
    </repositories>
...

How is it that the Maven build does not even attempt to reach out to https://artifacts.example.com/repository/maven/ to try to find the missing dependency shrinkwrap-bom? and only reaches out to the above repos only and not the one defined in my own pom.xml?

This seems like a transitive dependency resolution bug to me as the Maven build does not even make a single attempt at trying to get shrinkwrap-bom from the <repository> that I have explicitly defined in my pom.xml. The (grand)parents of the spring-boot-starter-web dependency completely hi-jack the repository list that the build pulls from (this type of hi-jacking should not be allowed). The shrinkwrap-bom artifact does exist in [https://artifacts.example.com/repository/maven/] and can be fetched no problem if it is explicitly defined in my pom.xml but defining it explicitly would be a work-around and I cannot use this work-around in my situation.


Affects: 3.0, 3.5.0, 3.5.2, 3.5.3, 3.6.0, 3.6.1, 3.6.3

Issue Links:

  • MNG-6772 Super POM overwrites remapped central repository in nested dependencyManagement import POMs
    ("is caused by")

  • MRESOLVER-168 add DEBUG message when downloading an artifact from repositories

  • MNG-7094 Assure in an IT that reactor repository definitions are not used when Model Builder downloads dependencies with scope import

Backported to: waiting-for-feedback

1 votes, 15 watchers

Activity

  1. jira-importer commented on Apr 19, 2018

    @jira-importer
    Author

    Karl Heinz Marbaise commented

    You should configure your repository manager correctly in your settings.xml and define a
    mirrorOf entry to redirect all request to your internal repository manager ...

    It also interesting to see things like this: : Connection reset -> [Help 1]... ?

  2. jira-importer commented on Apr 20, 2018

    @jira-importer
    Author

    Alan Czajkowski commented

    Karl Heinz Marbaise

    1. I appreciate your "work around" suggestion, and I've already thought of trying this, but this is not an acceptable solution for me as this build goes into a build system where I am not able to modify any settings.xml file. Everything related to the build must be completely self-contained inside the pom.xml, as this is a natural expectation of Maven, hence why I am logging this as a "bug" because the build should work naturally without me having to define mirrors.

    2. It is not interesting to see Connection reset because at the very beginning of the description I explained the firewall situation. The firewall here is not causing anything to break in Maven. Maven is simply ignoring/not respecting my <repository> definition in my own pom.xml.

  3. jira-importer commented on May 9, 2018

    @jira-importer
    Author

    Alan Czajkowski commented

    Work-around #1:

    • use mirrors inside settings.xml
    ...
    <mirrors>
      <mirror>
        <id>mirror-1</id>
        <name>Mirror - 1</name>
        <url>https://artifacts.example.com/repository/maven/</url>
        <mirrorOf>spring-milestone</mirrorOf>
      </mirror>
      <mirror>
        <id>mirror-2</id>
        <name>Mirror - 2</name>
        <url>https://artifacts.example.com/repository/maven/</url>
        <mirrorOf>spring-snapshot</mirrorOf>
      </mirror>
      <mirror>
        <id>mirror-3</id>
        <name>Mirror - 3</name>
        <url>https://artifacts.example.com/repository/maven/</url>
        <mirrorOf>rabbit-milestone</mirrorOf>
      </mirror>
    </mirrors>
    ...

    Work-around #2:

    • restate the hi-jacking repositories inside your pom.xml, keep the <id> tags the same, and then do your own hi-jacking of the <url> tags inside the <repository> definitions, like so:
    ...
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>spring-milestone</id>
      <name>Spring Milestone</name>
      <!-- # hi-jacked URL -->
      <url>https://artifacts.example.com/repository/maven/</url>
    </repository>
    <repository>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <id>spring-snapshot</id>
      <name>Spring Snapshot</name>
      <!-- # hi-jacked URL -->
      <url>https://artifacts.example.com/repository/maven/</url>
    </repository>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>rabbit-milestone</id>
      <name>Rabbit Milestone</name>
      <!-- # hi-jacked URL -->
      <url>https://artifacts.example.com/repository/maven/</url>
    </repository>
    ...
  4. jira-importer commented on May 9, 2018

    @jira-importer
    Author

    Alan Czajkowski commented

    is anybody looking into this bug?

  5. jira-importer commented on May 9, 2018

    @jira-importer
    Author

    Karl Heinz Marbaise commented

    If you don't like my "work around" sorry...the settings.xml is the solution to that particular problem. If you have already a build system this should already being configured correctly that way otherwise it not correctly configured (for example you should use config file provider plugin which offers this exactly for the settings.xml) ...

    I would suggest to define a <mirrorOf>*</mirrorOf> which is easier...

    The point is that you are expecting to overwrite the repository definitions of the dependencies/transitive dependencies which is not possible by using a repository entry in the pom.

    The point is that each pom/artifact maintainer can put repository definitions into their pom file (which is not a good idea cause it exactly happens what here is described...different story)...which results in exactly this situation. There for you have the option via settings.xml and define a mirror which redirects all request from each pom through the given mirror.

    If you don't like the solution or is not acceptable for you than please provide a patch(es) to solve it the way you like it...

  6. jira-importer commented on May 9, 2018

    @jira-importer
    Author

    Alan Czajkowski commented

    Karl Heinz Marbaise
    To be clear: this is a bug that needs to be fixed

    "The point is that you are expecting to overwrite the repository definitions of the dependencies/transitive dependencies which is not possible by using a repository entry in the pom." <-- this is not true, my simple expectation is that the Maven build at least try to attempt to reach out to the repo that i have in my own pom.xml alongside the repos defined in the dependency pom.xml <-- this is a reasonable expectation of Maven

    Your dependencies whether transitive or not, should not be allowed to do a complete hi-jacking of the list of repositories that the Maven build pulls from, which is what is happening here <-- that is the bug, the hi-jacking part

    the mirror work-around is not possible as i am not allowed to modify the current build system in place, which means the only way forward is to either explicitly define all of the problematic dependencies in my pom.xml (a very tedious and horrible solution), or do the second work-around i mentioned above by re-hi-jacking the repos again ... none of these work-arounds are ideal, nor do they follow reasonable expectations of Maven

  7. jira-importer commented on Jun 24, 2019

    @jira-importer
    Author

    Alan Czajkowski commented

    this is a common problem that comes up regularly in the various projects that I work on (especially projects that use Spring Boot and the Spring Boot parent in their projects), and I have to use the mirror work-around in the settings.xml (which is a poor solution)

    is anybody looking into this?

  8. jira-importer commented on Oct 1, 2019

    @jira-importer
    Author

    Eddie Wiegers commented

    I just ran into a similar-sounding issue that based on your build output looks like it may be the same root cause. I have logged a separate issue (MNG-6772) to provide my investigation notes, but wanted to give a heads up that it looks like the same root issue.

  9. jira-importer commented on Oct 1, 2019

    @jira-importer
    Author

    Alan Czajkowski commented

    Eddie Wiegers unfortunately, I don't think anybody is looking into this or taking it seriously :(

  10. jira-importer commented on Oct 4, 2019

    @jira-importer
    Author

    Eddie Wiegers commented

    I submitted a fix, so if it gets accepted hopefully this will be resolved in Maven 3.6.3.

  11. jira-importer commented on Oct 4, 2019

    @jira-importer
    Author

    Alan Czajkowski commented

    Eddie Wiegers amazing, thank you!

  12. jira-importer commented on Nov 9, 2019

    @jira-importer
    Author

    Fan Guogang commented

    mirrorOf * is not a good option, for example if you use a hosted repository server, such as nexus or artifactory, you need to create a group contains all repositories,that will cause slow performance when resloving dependencies, because nexus will need to contact all repositories to get metadata.

  13. jira-importer commented on Feb 10, 2020

    @jira-importer
    Author

    Alan Czajkowski commented

    Karl Heinz Marbaise can we get Eddie Wiegers's fix accepted?

  14. jira-importer commented on Feb 25, 2020

    @jira-importer
    Author

    Elliotte Rusty Harold commented

    sounds like the decision here is won't fix, WAI. Should we close the bug?

  15. jira-importer commented on Feb 26, 2020

    @jira-importer
    Author

    Alan Czajkowski commented

    why would this be closed? this is a legitimate problem with Maven dependency resolution, and becoming a more prominent problem with the proliferation of Spring Boot

  16. 10 remaining items

  17. jira-importer commented on Aug 29, 2020

    @jira-importer
    Author

    brian clozel commented

    This issue bothers me in many ways.

    ??Spring Boot takes the non-standard approach of forcing you to reference their parent POM instead of simply just referencing Spring Boot as a dependency in your project POM. As a result, the dependency graph is hi-jacked by Spring Boot because the graph root does not hinge on your project POM as the root of the graph, like it would in a normal Maven project, instead your project POM just becomes a child in the puppet-mastery of the Spring Boot parent POM, and you, as a developer, are no longer in control of the build in its entirety – and this scenario of "loss of control" has exposed a certain edge-case bug in how all of the dependencies of the entire dependency graph get downloaded.??

    First, there are many ways to use Spring Boot: you can choose a build tool, or just import spring-boot-dependencies as a BOM and take full control of your POM hierarchy. We do recommend importing the Spring Boot parent (and that's what we do on start.spring.io), because we think this is the best approach to support our users on Maven. How is this approach "non standard" and what is the standard you're referring to? Of course Spring libraries can be consumed as regular dependencies, but in this case Spring Boot does much more than a library.

    Also, why people here would assume that Spring Boot is forcing those repositories declarations on purpose? Do Spring projects have an history of being bad Maven citizens?
    A quick look on search.maven.org shows that Spring Boot 2.0.0.RELEASE is the only version declaring those repositories in our dependencies module. Another quick search in the Spring Boot tracker shows that we noticed that problem ourselves and this was quickly addressed in 2.0.1.RELEASE, released a month after 2.0.0.RELEASE.

    Finally, why are Spring developers being pulled here for a one-off, 2 year-old problem on a POM (fixed a month after it appeared) on a Spring Boot generation that is now EOL? The best workaround here is to upgrade to 2.0.1.RELEASE or better, upgrade to a version that is suported officially by the Spring team.

    If there are any issues with POMs Spring Boot is publishing, please create an issue on our tracker.

  18. jira-importer commented on Aug 31, 2020

    @jira-importer
    Author

    Alan Czajkowski commented

    brian clozel

    To be clear, this issue that I have raised in this ticket, is something that I believe is a bug in how Maven decides to download the entire dependency graph if it is not rooted at your project's POM (i.e. referring to a parent POM makes your project not the root of the dependency graph). I'm not blaming Spring Boot for this problem, this is a Maven problem.

    That being said ... there's plenty to rant about Spring Boot's approach. This ticket is not the appropriate place to do it, but i'll do it anyway since you're here ...

    As for Spring Boot, what is non-standard about referring to a parent POM for an external dependency (such as Spring Boot)?

    1. We can start with the hi-jacking of the resource filtering start/end tokens, where the default is ${ and } and Spring Boot forces you to use @ instead: this is a major intrusion to a project. I completely understand why Spring Boot chose to do this, so that Maven's resource filtering and variable interpolation does not conflict with Spring's Expression Language (SpEL), but still ...
    2. Many enterprises create parent POMs for the entire organization, to standardize certain build configurations across all builds for the entire organization. Maven does not support referencing 2 parent POMs, so if you reference the Spring Boot parent POM (which is the highly recommended way to do a Spring Boot project) then it completely breaks the ability to reference the enterprise's parent POM to inherit important build configuration. I know there are ways around this, like creating a intermediary parent POM that sits between the Spring Boot parent and the project, and then the project references that intermediary parent POM, but that is just doing painful build gymnastics, and not fun to maintain.
  19. jira-importer commented on Aug 31, 2020

    @jira-importer
    Author

    Stephane Nicoll commented

    Spring Boot forces you to use @ instead:

    It doesn't do that in any way. As Brian indicated, you don't have to use the parent if you don't want to (have you looked at the references he shared before replying)? Even if you do, you can easily override the resources filtering configuration to use whatever placeholders you fancy.

    if you reference the Spring Boot parent POM (which is the highly recommended way to do a Spring Boot project)

    Given the italics in "highly", I suspect you believe that's true. It isn't.

    I think Brian already showcased we're happy to improve things based on constructive feedback. Spring Boot lets you chose your own parent. You can chose to import our BOM there or manage things yourself completely. Of course, doing so may mean more work for you.

  20. jira-importer commented on Aug 31, 2020

    @jira-importer
    Author

    Alan Czajkowski commented

    Stephane Nicoll this ticket was created in 2018, way before any of that "convenient" Spring Boot documentation existed or BOM options were available ...

    once again, this ticket is for a bug-fix in Maven, not for Spring Boot to improve anything, because if someone chooses to go the Spring Boot parent POM route, and they are sitting behind a firewall that blocks internet access, then they are going to run into this Maven issue

  21. jira-importer commented on Sep 1, 2020

    @jira-importer
    Author

    Sylwester Lachiewicz commented

    Alan Czajkowski I've merged changes for MNG-6772 to master, please check if this also resolved your case. 

    Please run build yourself or use artifacts for 3.70-SNAPSHOT from our Jenkins: https://ci-builds.apache.org/job/Maven/job/maven-box/job/maven/job/master/

  22. jira-importer commented on Nov 23, 2020

    @jira-importer
    Author

    Alan Czajkowski commented

    Michael Osipov why does this add a loop-hole? all this this ticket requests is that dependency resolution include whatever repositories are mentioned in the project's pom.xml, not override anything in parent and/or sibling pom.xml files in the dependency tree

    therefore if we are not overriding, why is this a problem?

  23. jira-importer commented on Dec 2, 2020

    @jira-importer
    Author

    Michael Osipov commented

    Alan Czajkowski, let me try a few tests behind Nexus. Also read my comments in MNG-6772. This is a duplicate issue for me. If not, please explain why.

  24. jira-importer commented on Dec 2, 2020

    @jira-importer
    Author

    Michael Osipov commented

    I applied the following patch to Core ITs:

    $ git diff
    diff --git a/core-it-suite/src/test/resources/mng-6772-override-in-dependency/pom-template.xml b/core-it-suite/src/test/resources/mng-6772-override-in-dependency/pom-template.xml
    index 9120768b..4e091a37 100644
    --- a/core-it-suite/src/test/resources/mng-6772-override-in-dependency/pom-template.xml
    +++ b/core-it-suite/src/test/resources/mng-6772-override-in-dependency/pom-template.xml
    @@ -43,7 +43,7 @@ under the License.
    
         <repositories>
             <repository>
    -            <id>central</id>
    +            <id>central2</id>
                 <url>@baseurl@/repo</url>
             </repository>
         </repositories>
    diff --git a/core-it-suite/src/test/resources/mng-6772-override-in-project/pom-template.xml b/core-it-suite/src/test/resources/mng-6772-override-in-project/pom-template.xml
    index 19149cd0..1604aa39 100644
    --- a/core-it-suite/src/test/resources/mng-6772-override-in-project/pom-template.xml
    +++ b/core-it-suite/src/test/resources/mng-6772-override-in-project/pom-template.xml
    @@ -46,7 +46,7 @@ under the License.
    
         <repositories>
             <repository>
    -            <id>central</id>
    +            <id>central2</id>
                 <url>@baseurl@/repo</url>
             </repository>
         </repositories>
    

    and the test passed. From my POV, as said before, the fix and tests are logically broken. If your problem differs present a different IT, I'd be happy to evaluate.

  25. jira-importer commented on Feb 9, 2021

    @jira-importer
    Author

    Hervé Boutemy commented

    just changed link to MNG-6772: the current issue is caused by MNG-6772 = handling of import-scoped dependencies (in dependencyManagement) by Model Builder does not work the same way as "normal" dependencies by lifecycle
    (no judgment at this stage if we should change that nor if we can: it's just a description of what is happening, that will be shown in future IT through MNG-7094)

  26. jira-importer commented on Apr 11, 2021

    @jira-importer
    Author

    Hervé Boutemy commented

    to ease debugging of repositories order when resolving an artifact, I implemented MRESOLVER-168

  27. added
    enhancement
    priority:critical
    on Jul 6, 2025
  28. modified the milestones: , 4.x on Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority:critical

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions