ProgrammerBoy
ProgrammerBoy

Reputation: 891

Why is Maven fetching the wrong Jetty version?

I am using spring boot and have below dependencies. If you look at the jetty dependencies, I expect it to fetch all the jetty dependencies with "9.4.1.v20170120" suffix but it's fetching the wrong version. I am using the same thing in another project where it fetches it correctly. Please take a look at images.

pom.xml entries:

<properties>
    <java.version>1.8</java.version>
    <junit.version>4.11</junit.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.1.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>
</dependencies>

enter image description here

Why is this happening?

Upvotes: 2

Views: 761

Answers (1)

Mike Adamenko
Mike Adamenko

Reputation: 3002

It is maven transitive dependency resolution.

By default Maven resolves version conflicts with a nearest-wins strategy

When resolving dependencies and there is a conflict between libraries Maven selects the library that is nearer to the root. In your case it is javax.servlet-api.3.1.0.jar

See https://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html

Upvotes: 3

Related Questions