javamavenokhttpmockwebserver

Maven dependencies wrong version for okhttp3 mockwebserver


I am trying to use okhttp3.mockwebserver with my Spring boot project and I find out that okhttp3:mockwebserver:jar:3.14.9 is included instead of 4.9.1.

I have created small 'mock' projects to reproduce the issue I have in my prod.

The project is here https://github.com/mkarasik/okhttp-test

It contains two folders:

lib

This is a simple library including mockwebserver as dependency

pom.xml dependency

    <dependencies>
    ...
    <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>mockwebserver</artifactId>
        <version>4.9.1</version>
        <exclusions>
            <exclusion>
                <artifactId>junit</artifactId>
                <groupId>junit</groupId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

Maven dependencies tree

 \- com.squareup.okhttp3:mockwebserver:jar:4.9.1:compile
    +- com.squareup.okhttp3:okhttp:jar:3.14.9:compile

This is already wrong. Mockwebserver pom contains 4.9.1 okhttp artifact, however 3.14.9 is shown in tree

project

Simple Spring Boot app including lib project

    <dependency>
        <groupId>com.example</groupId>
        <artifactId>lib</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <scope>test</scope>
    </dependency>

Maven dependencies tree

\- com.example:lib:jar:0.0.1-SNAPSHOT:test
   \- com.squareup.okhttp3:mockwebserver:jar:3.14.9:test
      \- com.squareup.okhttp3:okhttp:jar:3.14.9:test
         \- com.squareup.okio:okio:jar:1.17.2:test

The same problem is here. okhttp3:mockwebserver:jar:3.14.9 is included instead of 4.9.1 as it is specified in my lib pom.xml.

Is there anything I am missing in my xml configuration?


Solution

  • Found it it it is described in Introducing dependencies in other projects causes Maven to downgrade okhttp3 version

    <properties>
        <okhttp3.version>4.9.1</okhttp3.version>
    </properties>
    

    Fixes the issue