Maven
  1. Maven
  2. MNG-4391

DependencyManagement should allow <replaceWith> to manage use of re-named, woven, instrumented or compatible artifacts

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: 2.2.1
    • Fix Version/s: None
    • Component/s: Dependencies
    • Labels:
      None
    • Complexity:
      Intermediate
    • Number of attachments :
      0

      Description

      [if only this was a later version of JIRA I'd have not lost all of what I just typed, as I could use Mylyn instead of the web UI. here goes again...]

      The challenge of using a different artifact instead of the one that is specified in a POM that you are consuming is not an easy one.

      Examples where this hits uses is:

      • the artifact name and packaging changes that Spring made at 2.5.6A (which was a big improvement)
      • wanting to use SLF4J instead of Apache commons logging (i.e. use something that provides the same API, but is an entirely different project)
      • wanting to use your own derivation of a public artifact
      • wanting to use a woven/instrumented version of a public artifact

      The current approach to replacing, say org.springframework : spring-beans with org.springframework : org.springframework.beans is to do ('scuse the shorthand):

      <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>jersey-spring</artifactId>
            <exclusions> 
                 org.springframework : spring-beans
            </exclusions>
          </dependency>
          ... repeat for every artifact that uses spring-beans, and then add more if adding another artifact
        </dependencies>
      </dependencyManagement>
      

      to exclude it, and then globally include the replacement using:

      <dependencies>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactid>org.springframework.beans</groupId>
          <version>${spring.version}</version>
        </dependency>
      </dependencies>
      

      This is error prone, and could be made far easier by an extension to dependencies, which would remove the need to know what artifacts (jersey-spring in the above example) use the artifact that you are replacing. Here's how it would look:

      <dependencyManagement>
        <!-- this declares the version we want to use if this artifact is in use -->
        <dependencies>
          <dependency>
            <groupId>org.springframework</groupId>
            <artifactid>org.springframework.beans</groupId>
            <version>${spring.version}</version>
          </dependency>
      
          <!-- This deals with artifact name change -->
          <dependency>
            <groupId>org.springframework</groupId>
            <artifactid>spring-beans</groupId>
            <replaceWith>  <!-- list of dependency elements -->
                <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactid>org.springframework.beans</groupId>
                </dependency>
                <!-- more dependency elements could be added here if an artifact has been split -->
            </replaceWith>
          </dependency>
      </dependencies>
      

      NOTE:

      • Nothing is specified in <dependencies> so no artifacts are globally added where they may not be needed. This means we can develop a project wide parent pom.xml.
      • Artifacts can have been split and merged
      • Derived artifacts, such as instrumented ones can easily be substituted, and could be selectively substituted using profiles.

        Activity

        Hide
        Paul Benedict added a comment -

        I don't think replacing is a good idea since it introduces a kind of relocation logic. Regardless, would adding global exclusions (MNG-1977) help?

        Show
        Paul Benedict added a comment - I don't think replacing is a good idea since it introduces a kind of relocation logic. Regardless, would adding global exclusions ( MNG-1977 ) help?
        Hide
        Neale added a comment - - edited

        I don't get your objection. What's the 'relocation logic' problem?

        Direct artifact substitution is what in many cases the developer needs, so surely the "good idea" test is whether it makes Maven easier to use and maintain.

        If you look at the comments on MNG-1977, you'll find David Jencks and Kees de Kooter suggesting the same as me.

        Show
        Neale added a comment - - edited I don't get your objection. What's the 'relocation logic' problem? Direct artifact substitution is what in many cases the developer needs, so surely the "good idea" test is whether it makes Maven easier to use and maintain. If you look at the comments on MNG-1977 , you'll find David Jencks and Kees de Kooter suggesting the same as me.
        Hide
        Paul Benedict added a comment -

        My objection is that the POM no longer reflects reality. If a POM can relocate an artifact, a child project configured to download X gets Y, but when I look at the child POM, it says download X. It's too much smoke-and-mirrors for me and is bound to lead to confusion.

        Show
        Paul Benedict added a comment - My objection is that the POM no longer reflects reality. If a POM can relocate an artifact, a child project configured to download X gets Y, but when I look at the child POM, it says download X. It's too much smoke-and-mirrors for me and is bound to lead to confusion.
        Hide
        Neale added a comment - - edited

        I think that's a rather personal point of view, if you don't mind me saying. On that basis, none of us would make use of AspectJ or proxies.

        It is already the case that a child project configured to download X gets Y, as that's what we're actually trying to do. The problem is that it doesn't actually say "replace X with Y". It says: "don't download X".

        You are mistaken in thinking that "when I look at the child POM, it says download X" is relevant to what we as developers need. We can easily end up with multiple versions of the same API on the classpath because the exclusions weren't set on every child.

        At some point in our project we want to say something like (as OSGi gives us): the implementation of org.apache.commons.logging that I want to use in my build and runtime can be found in org.slf4j:slf4j:org.apache.commons.logging, or, if we want one that has been built as a valid OSGi bundle: org.slf4j:com.springsource.slf4j.org.apache.commons.logging.

        What we certainly don't want is to have to repeat the exclude on an ad-hoc basis, and nor do we want the meaning lost in separating out an exclusion with a global inclusion (which is not always wanted either - e.g. for corporate standards).

        Can you please tell me how you propose to satisfy this use case, if you still have your objections to my solution. It's all very well disagreeing, but it would be useful to offer a better solution in it's place.

        Show
        Neale added a comment - - edited I think that's a rather personal point of view, if you don't mind me saying. On that basis, none of us would make use of AspectJ or proxies. It is already the case that a child project configured to download X gets Y, as that's what we're actually trying to do. The problem is that it doesn't actually say "replace X with Y". It says: "don't download X". You are mistaken in thinking that "when I look at the child POM, it says download X" is relevant to what we as developers need. We can easily end up with multiple versions of the same API on the classpath because the exclusions weren't set on every child. At some point in our project we want to say something like (as OSGi gives us): the implementation of org.apache.commons.logging that I want to use in my build and runtime can be found in org.slf4j:slf4j:org.apache.commons.logging , or, if we want one that has been built as a valid OSGi bundle: org.slf4j:com.springsource.slf4j.org.apache.commons.logging . What we certainly don't want is to have to repeat the exclude on an ad-hoc basis, and nor do we want the meaning lost in separating out an exclusion with a global inclusion (which is not always wanted either - e.g. for corporate standards). Can you please tell me how you propose to satisfy this use case, if you still have your objections to my solution. It's all very well disagreeing, but it would be useful to offer a better solution in it's place.
        Hide
        Paul Benedict added a comment -

        >> I think that's a rather personal point of view, if you don't mind me saying.
        Of course it's a personal point of view.

        >> It is already the case that a child project configured to download X gets Y
        The use case is limited. X represents the artifact. You may configure different versions of X for downloading, but it's still artifact X. Maven does provide relocation support, but it's controlled by the publisher of the artifact. You are expanding its use to give people the ability to relocate (temporarily) for the current execution. Well, I don't think it's a good idea because it makes the POM unclear what is going on.

        Show
        Paul Benedict added a comment - >> I think that's a rather personal point of view, if you don't mind me saying. Of course it's a personal point of view. >> It is already the case that a child project configured to download X gets Y The use case is limited. X represents the artifact. You may configure different versions of X for downloading, but it's still artifact X. Maven does provide relocation support, but it's controlled by the publisher of the artifact. You are expanding its use to give people the ability to relocate (temporarily) for the current execution. Well, I don't think it's a good idea because it makes the POM unclear what is going on.
        Hide
        Neale added a comment - - edited

        >> You may configure different versions of X for downloading, but it's still artifact X.

        That is exactly the problem. If my project, A depends on X which has a transitive dependency on Y, then being able to vary the version of Y does not allow us to substitute (yet does allow us to break the software by allowing us to regress a version from, say 2.1 to 1.3.

        Please notice ththat other's are now voting and consider this request.

        It's an option, and you are pre-judging the intent of an artifact's developer to presume that they, under no circumstances want anyone to replace a dependency with an alternative that may be

        • instrumented
        • woven
        • enhanced (e.g. the trunk committers don't have the time/inclination to implement a feature or fix that you need)
        • bug fixed in a (local or public) branch
        • project naturally branched and the branch became the mainstream version

        That presumption is simply not true.

        So. I ask again. Can you please tell me how I, in a way where my intent is as clear as water, replace Apache Commons Logging with the SLF4J Apache Commons Logging integration artifact?

        Show
        Neale added a comment - - edited >> You may configure different versions of X for downloading, but it's still artifact X. That is exactly the problem. If my project, A depends on X which has a transitive dependency on Y, then being able to vary the version of Y does not allow us to substitute (yet does allow us to break the software by allowing us to regress a version from, say 2.1 to 1.3. Please notice ththat other's are now voting and consider this request. It's an option, and you are pre-judging the intent of an artifact's developer to presume that they, under no circumstances want anyone to replace a dependency with an alternative that may be instrumented woven enhanced (e.g. the trunk committers don't have the time/inclination to implement a feature or fix that you need) bug fixed in a (local or public) branch project naturally branched and the branch became the mainstream version That presumption is simply not true. So. I ask again. Can you please tell me how I, in a way where my intent is as clear as water, replace Apache Commons Logging with the SLF4J Apache Commons Logging integration artifact?
        Hide
        Stevo Slavic added a comment -

        Why not just support dependencies section for a dependency, like what's already supported for build plugins (and hopefully will be in v3 supported for reporting plugins too)? One could then for a given dependency configure set of exclusions and add dependencies too out of which some could be exclusion replacements. Dependency POM no longer reflects reality once one adds exclusions to it, so adding more dependencies to it will IMO not be much more difference on that aspect - there's always dependency:tree and dependency:analyze, and IDE plugins can visualize effective POM.

        Show
        Stevo Slavic added a comment - Why not just support dependencies section for a dependency, like what's already supported for build plugins (and hopefully will be in v3 supported for reporting plugins too)? One could then for a given dependency configure set of exclusions and add dependencies too out of which some could be exclusion replacements. Dependency POM no longer reflects reality once one adds exclusions to it, so adding more dependencies to it will IMO not be much more difference on that aspect - there's always dependency:tree and dependency:analyze, and IDE plugins can visualize effective POM.
        Hide
        Paul Benedict added a comment -

        Stevo, that is a very interesting idea.

        Show
        Paul Benedict added a comment - Stevo, that is a very interesting idea.
        Hide
        Neale added a comment - - edited

        Agree too. That'd do the trick and sounds like it'd be a helpful way of ensuring tools such as m2e can visualise the results easily. Nice one.

        Show
        Neale added a comment - - edited Agree too. That'd do the trick and sounds like it'd be a helpful way of ensuring tools such as m2e can visualise the results easily. Nice one.
        Hide
        Neale added a comment -

        Can we please have a resolution to this issue for 3.1. The challenge of artifacts where we want provide an alternative implementation needs to be clear. The POM configuration should represent the intent: "Where dependency groupId:artifactId is specified, I want to use replacementGroupId:replacementArtifactId instead"

        Show
        Neale added a comment - Can we please have a resolution to this issue for 3.1. The challenge of artifacts where we want provide an alternative implementation needs to be clear. The POM configuration should represent the intent: "Where dependency groupId:artifactId is specified, I want to use replacementGroupId:replacementArtifactId instead"
        Hide
        Sören Chittka added a comment -

        +1 for having this in 3.1

        I really like the syntax suggested above. It makes clear what is intended. If this is to much 'smoke-and-mirrors' a decent IDE can make visible what is going on.

        Show
        Sören Chittka added a comment - +1 for having this in 3.1 I really like the syntax suggested above. It makes clear what is intended. If this is to much 'smoke-and-mirrors' a decent IDE can make visible what is going on.
        Show
        Jason van Zyl added a comment - Please refer to https://cwiki.apache.org/confluence/display/MAVEN/The+Great+JIRA+Cleanup+of+2014
        Hide
        Jason van Zyl added a comment -

        Please refer to https://cwiki.apache.org/confluence/display/MAVEN/The+Great+JIRA+Cleanup+of+2014 if you're wondering why this issue was closed out.

        Show
        Jason van Zyl added a comment - Please refer to https://cwiki.apache.org/confluence/display/MAVEN/The+Great+JIRA+Cleanup+of+2014 if you're wondering why this issue was closed out.

          People

          • Assignee:
            Unassigned
            Reporter:
            Neale
          • Votes:
            9 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: