You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Fabian Christ (JIRA)" <ji...@codehaus.org> on 2006/11/21 12:41:31 UTC

[jira] Created: (MNG-2672) Wrong dependency handling when having dependencies to artifacts in different versions

Wrong dependency handling when having dependencies to artifacts in different versions
-------------------------------------------------------------------------------------

                 Key: MNG-2672
                 URL: http://jira.codehaus.org/browse/MNG-2672
             Project: Maven 2
          Issue Type: Bug
          Components: Dependencies
    Affects Versions: 2.0.4
         Environment: Windows XP, JDK 1.4.2_12
            Reporter: Fabian Christ


Hi,

let's take a look at the following situation. There is a project A which has dependencies to B and C. Now both B and C have a dependency to D but in different versions. B requires version D-1.0 and C version D-2.0.

Now in different situations is one time D-1.0 used and the next time D-2.0. There is no chance to configure which version will be used. Notice the restriction that I can't change the configured dependencies in B oder C - they are given.Here is a list of different configurations and their results:

Base configuration:

A:
<dependency>
  <groupId>org.test</groupId>
  <artifactId>B</artifactId>
  <version>1.0-SNAPSHOT</version>
  <scope>compile</scope>
</dependency>

<dependency>
  <groupId>org.test</groupId>
  <artifactId>C</artifactId>
  <version>1.0-SNAPSHOT</version>
  <scope>compile</scope>
</dependency>

B:
<dependency>
  <groupId>org.test</groupId>
  <artifactId>D</artifactId>
  <version>1.0</version>
  <scope>compile</scope>
</dependency>

C:
<dependency>
  <groupId>org.test</groupId>
  <artifactId>D</artifactId>
  <version>2.0</version>
  <scope>compile</scope>
</dependency>

Debug:
[DEBUG] org.test:A:jar:1.0 (selected for null)
[DEBUG]   org.test:B:jar:1.0-SNAPSHOT:compile (selected for compile)
[DEBUG]     org.test:D:jar:1.0:compile (selected for compile)
[DEBUG]   org.test:C:jar:1.0-SNAPSHOT:compile (selected for compile)
[DEBUG]     org.test:D:jar:2.0:compile (removed - nearer found: 1.0)

=> so D-1.0.jar is used

Config 2:
Exclude artifact D from dependency on B in A:
<dependency>
  <groupId>org.test</groupId>
  <artifactId>B</artifactId>
  <version>1.0-SNAPSHOT</version>
  <scope>compile</scope>
  <exclusions>
    <exclusion>
      <groupId>org.test</groupId>
      <artifactId>D</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Debug:
[DEBUG] org.test:A:jar:1.0 (selected for null)
[DEBUG]   org.test:B:jar:1.0-SNAPSHOT:compile (selected for compile)
[DEBUG]   org.test:C:jar:1.0-SNAPSHOT:compile (selected for compile)

==> So D is never used (!) and so not on the classpath. Expected was to use D-2.0. The exclude seems not to work correct here as it excludes the artifact from the whole build.

Config 3:
No exclusions.
Change dependency of A to B-1.0-SNAPSHOT to B-1.0

Debug:
[DEBUG] org.test:A:jar:1.0 (selected for null)
[DEBUG]   org.test:C:jar:1.0-SNAPSHOT:compile (selected for compile)
[DEBUG]     org.test:D:jar:2.0:compile (selected for compile)
[DEBUG]   org.test:B:jar:1.0:compile (selected for compile)
[DEBUG]     org.test:D:jar:1.0:compile (removed - nearer found: 2.0)

==> so D-2.0.jar is used (!). Why is version 2.0 nearer now than 1.0? In the base configuration above version 1.0 was nearer.

Config 4:
Change dependency of A to B-1.0-SNAPSHOT to B-1.0
Change dependency of A to C-1.0-SNAPSHOT to C-1.0

Debug:
[DEBUG] org.test:A:jar:1.0 (selected for null)
[DEBUG]   org.test:C:jar:1.0:compile (selected for compile)
[DEBUG]     org.test:D:jar:2.0:compile (selected for compile)
[DEBUG]   org.test:B:jar:1.0:compile (selected for compile)
[DEBUG]     org.test:D:jar:1.0:compile (removed - nearer found: 2.0)

==> so D-2.0.jar is used. Same result as with config 3.

So what would be the correct behavior here? At the moment it is not configurable which version of D will be used during compile. 

- Fabian

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Closed: (MNG-2672) Wrong dependency handling when having dependencies to artifacts in different versions

Posted by "Carlos Sanchez (JIRA)" <ji...@codehaus.org>.
     [ http://jira.codehaus.org/browse/MNG-2672?page=all ]

Carlos Sanchez closed MNG-2672.
-------------------------------

      Assignee: Carlos Sanchez
    Resolution: Won't Fix

Works as expected, check http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

i've just improved the docs and will be available soon

# Dependency mediation - this determines what version of a dependency will be used when multiple versions of an artifact are encountered. Currently, Maven 2.0 only supports using the "nearest definition" which means that it will use the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM. Note that if two dependency versions are at the same depth in the dependency tree it's not defined which one will win.

    * "nearest definition" means that the version used will be the closest one to your project in the tree of dependencies, eg. if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0

> Wrong dependency handling when having dependencies to artifacts in different versions
> -------------------------------------------------------------------------------------
>
>                 Key: MNG-2672
>                 URL: http://jira.codehaus.org/browse/MNG-2672
>             Project: Maven 2
>          Issue Type: Bug
>          Components: Dependencies
>    Affects Versions: 2.0.4
>         Environment: Windows XP, JDK 1.4.2_12
>            Reporter: Fabian Christ
>         Assigned To: Carlos Sanchez
>
> Hi,
> let's take a look at the following situation. There is a project A which has dependencies to B and C. Now both B and C have a dependency to D but in different versions. B requires version D-1.0 and C version D-2.0.
> Now in different situations is one time D-1.0 used and the next time D-2.0. There is no chance to configure which version will be used. Notice the restriction that I can't change the configured dependencies in B oder C - they are given.Here is a list of different configurations and their results:
> Base configuration:
> A:
> <dependency>
>   <groupId>org.test</groupId>
>   <artifactId>B</artifactId>
>   <version>1.0-SNAPSHOT</version>
>   <scope>compile</scope>
> </dependency>
> <dependency>
>   <groupId>org.test</groupId>
>   <artifactId>C</artifactId>
>   <version>1.0-SNAPSHOT</version>
>   <scope>compile</scope>
> </dependency>
> B:
> <dependency>
>   <groupId>org.test</groupId>
>   <artifactId>D</artifactId>
>   <version>1.0</version>
>   <scope>compile</scope>
> </dependency>
> C:
> <dependency>
>   <groupId>org.test</groupId>
>   <artifactId>D</artifactId>
>   <version>2.0</version>
>   <scope>compile</scope>
> </dependency>
> Debug:
> [DEBUG] org.test:A:jar:1.0 (selected for null)
> [DEBUG]   org.test:B:jar:1.0-SNAPSHOT:compile (selected for compile)
> [DEBUG]     org.test:D:jar:1.0:compile (selected for compile)
> [DEBUG]   org.test:C:jar:1.0-SNAPSHOT:compile (selected for compile)
> [DEBUG]     org.test:D:jar:2.0:compile (removed - nearer found: 1.0)
> => so D-1.0.jar is used
> Config 2:
> Exclude artifact D from dependency on B in A:
> <dependency>
>   <groupId>org.test</groupId>
>   <artifactId>B</artifactId>
>   <version>1.0-SNAPSHOT</version>
>   <scope>compile</scope>
>   <exclusions>
>     <exclusion>
>       <groupId>org.test</groupId>
>       <artifactId>D</artifactId>
>     </exclusion>
>   </exclusions>
> </dependency>
> Debug:
> [DEBUG] org.test:A:jar:1.0 (selected for null)
> [DEBUG]   org.test:B:jar:1.0-SNAPSHOT:compile (selected for compile)
> [DEBUG]   org.test:C:jar:1.0-SNAPSHOT:compile (selected for compile)
> ==> So D is never used (!) and so not on the classpath. Expected was to use D-2.0. The exclude seems not to work correct here as it excludes the artifact from the whole build.
> Config 3:
> No exclusions.
> Change dependency of A to B-1.0-SNAPSHOT to B-1.0
> Debug:
> [DEBUG] org.test:A:jar:1.0 (selected for null)
> [DEBUG]   org.test:C:jar:1.0-SNAPSHOT:compile (selected for compile)
> [DEBUG]     org.test:D:jar:2.0:compile (selected for compile)
> [DEBUG]   org.test:B:jar:1.0:compile (selected for compile)
> [DEBUG]     org.test:D:jar:1.0:compile (removed - nearer found: 2.0)
> ==> so D-2.0.jar is used (!). Why is version 2.0 nearer now than 1.0? In the base configuration above version 1.0 was nearer.
> Config 4:
> Change dependency of A to B-1.0-SNAPSHOT to B-1.0
> Change dependency of A to C-1.0-SNAPSHOT to C-1.0
> Debug:
> [DEBUG] org.test:A:jar:1.0 (selected for null)
> [DEBUG]   org.test:C:jar:1.0:compile (selected for compile)
> [DEBUG]     org.test:D:jar:2.0:compile (selected for compile)
> [DEBUG]   org.test:B:jar:1.0:compile (selected for compile)
> [DEBUG]     org.test:D:jar:1.0:compile (removed - nearer found: 2.0)
> ==> so D-2.0.jar is used. Same result as with config 3.
> So what would be the correct behavior here? At the moment it is not configurable which version of D will be used during compile. 
> - Fabian

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira