Anand Sunderraman
Anand Sunderraman

Reputation: 8148

Maven determine what version of the dependency is being used

I have inherited a maven project (I am still learning maven).

The project has 3 modules there is a parent pom that the 3 modules inherit from.

I need to make changes to a pom.xml for some changes requested.

After I made the changes and run the project I got the error.

Caused by: java.lang.ClassNotFoundException: org.quartz.spi.ClassLoadHelper

So I noticed that my pom.xml had the exclusion as follows:

   <dependency>
        <groupId>com.mycompany</groupId>
        <artifactId>framework</artifactId>
        <version>1.0.9</version>
        <exclusions>
            <exclusion>
                <groupId>org.quartz-scheduler</groupId>
                <artifactId>quartz</artifactId>
            </exclusion>
        <exclusion>
    </dependency>

So I removed the exclusion and ran the project again to get the following error

    Caused by: java.lang.IncompatibleClassChangeError: 
class org.springframework.scheduling.quartz.CronTriggerBean 
has interface org.quartz.CronTrigger as super class

So looks like the exclusion was meant to be because some other dependency was satisfying the quartz dependency.

And looks like after I added new dependencies somehow the quartz dependency has been excluded.

My question is:

How do I determine what was bringing in the quartz dependency ? How do I ensure that by adding new dependencies I do not exclude the existing quartz dependency ?

Upvotes: 1

Views: 2362

Answers (3)

asg
asg

Reputation: 2456

Maven follows - 'Dependency mediation' algorithm to choose between dependencies. Rules are:

  1. Nearest first: A dependency of lower level has a priority over
    another of the higher depth. (Here, level refers to 1st level, 2nd
    level transitive dependency etc.) And hence, a direct dependency has
    priority over transitive dependency.

  2. First Found - At the same level, the first dependency that is found is taken.

So to determine which dependency was bringing in the Quartz dependency, take a look at the dependency hierarchy of your pom.xml - http://books.sonatype.com/m2eclipse-book/reference/dependencies-sect-analyze-depend.html#fig-dependencies-pom-editor-locate-depend

And to make sure that you are not loosing your current quartz dependency, add it as a direct dependency in your pom.xml. This will override all your quartz transitive dependencies.

Upvotes: 0

aengus
aengus

Reputation: 606

Take a look at the command

    mvn dependency:tree 

Upvotes: 3

pens-fan-69
pens-fan-69

Reputation: 1039

You can view the maven dependency tree to see what was bringing in the quartz dependency.

Upvotes: 0

Related Questions