Maven 2 & 3

[regression] Optional flag from dependency management applied to dependencies

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 3.0-alpha-7
  • Fix Version/s: 3.0-beta-1
  • Component/s: Dependencies
  • Labels:
    None
  • Environment:
  • Complexity:
    Intermediate
  • Testcase included:
    yes
  • Number of attachments :
    1

Description

The situation is quite complex to explain. I've a parent pom that defines dependencies in depMgmt. There's two projects in the multimodule project, the second depending on the first.

Excerpt (parent/depMgmt):
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>runtime</scope>
<optional>true</optional>

First child (redefines scope only):
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>compile</scope>
</dependency>

Second child:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>m3pb</groupId>
<artifactId>subproject1</artifactId>
<version>${project.version}</version>
</dependency>

When running with maven 2, it works. When ran with maven 3, it fails on the second project, with a NoClassDefFoundError on the logback jar.

I seem to understand this is actually a bug in maven 2: as the depMgmt defines optional=true, it shouldn't have been working in maven2 without redeclaring the dependency in the second project.

From my understanding:

  • With maven 2, the transivity is taken in account and gives logback through the subproject1 link (from the second)
  • With maven 3, this just doesn't work and this is the correct behaviour.

Please excuse my basic analysis.
I'm attaching a test project to let see more precisely the problem.

If you need any help, please let me know.

Cheers
-- 
Baptiste

Issue Links

Activity

Hide
Baptiste MATHUS added a comment -

An addon, to show the difference with mvn dependency:tree:

With maven3:
Nothing

With Maven 2.2.1:
[INFO] m3pb:sub2:jar:1.0-SNAPSHOT
[INFO] - m3pb:subproject1:jar:1.0-SNAPSHOT:compile
[INFO] - ch.qos.logback:logback-classic:jar:0.9.14:runtime (scope managed from compile)
[INFO] - ch.qos.logback:logback-core:jar:0.9.14:runtime

Cheers

Show
Baptiste MATHUS added a comment - An addon, to show the difference with mvn dependency:tree: With maven3: Nothing With Maven 2.2.1: [INFO] m3pb:sub2:jar:1.0-SNAPSHOT [INFO] - m3pb:subproject1:jar:1.0-SNAPSHOT:compile [INFO] - ch.qos.logback:logback-classic:jar:0.9.14:runtime (scope managed from compile) [INFO] - ch.qos.logback:logback-core:jar:0.9.14:runtime Cheers
Hide
Benjamin Bentmann added a comment -

Fixed in r925481, thanks for the example project.

Show
Benjamin Bentmann added a comment - Fixed in r925481, thanks for the example project.
Hide
Baptiste MATHUS added a comment -

Verified with mvn 3.0 SNAPSHOT (compiled from trunk, r925570) on the original project=>OK.

Thanks a lot.

Show
Baptiste MATHUS added a comment - Verified with mvn 3.0 SNAPSHOT (compiled from trunk, r925570) on the original project=>OK. Thanks a lot.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: