pkaramol
pkaramol

Reputation: 19342

Maven: dependency appears in effective pom but not in dependency tree

Working on a multi-module project.

GrandParent
        \
         Parent
             \
             Child

GrandParent has rogue_1 module in its <dependencyManagement> section as provided !

Parent does NOT have rogue_1 in its pom.xml at all.

Child does NOT have rogue_1 as a direct dependency in its pom.xml.

However it includes several other projects some of which may include rogue_1. (at least one does depend on rogue_1)

To be on the safe side, on ALL Child's dependencies I have added exclusions as follows:

<dependency> <!-- a direct dependency of Child -->
    <groupId>erso</groupId>
    <artifactId>galen</artifactId>
    <exclusions>
        <exclusion>
            <groupId>resistance</groupId>
            <artifactId>rogue_1</artifactId>
        </exclusion>
    </exclusions>
</dependency>

(in case for example galen.erso is bringing in the resistance.rogue_1)

However: rogue_1 DOES end up being displayed as a dependency in the outcome of

mvn help:effective-pom

(as provided !)

It is NOT in the ouctome of

mvn dependency:tree

Any suggestions?

Upvotes: 11

Views: 10429

Answers (2)

carlspring
carlspring

Reputation: 32617

You may get this sort of behaviour, if you have a profile either in your project, or one that you're inheriting (and that is somehow getting activated). As far as I recall, dependencies defined in a <profile/> do not show up on the dependency tree.

Upvotes: 1

Naman
Naman

Reputation: 31878

mvn help:effective-pom

is basically a merger between the super POM (grand /+parent) dependencies and the simple POM that you defined at the project level. Hence you do see the rogue_1 under the XML created by effective-pom, of course your grandparent pom's dependencyManagement being the source. Here is a detailed read over the same.

mvn dependency:tree

on the other hand displays the tre of the dependencies used in your project. As you mentioned you've excluded this out of all your mentioned dependencies, so you shouldn't find the artifact listed here.

By the way, in both the cases the chances of having the rogue_1 in the classpath of your child module is zero.

Upvotes: 9

Related Questions