Alexander Zacharuk
Alexander Zacharuk

Reputation: 53

Why can't I use an apache httpcomponents object in spring-boot, even though it is listed in the MVN dependancies?

Spring-boot has the following maven dependencies around org.apache.httpcomponents

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpasyncclient</artifactId>
    <version>${httpasyncclient.version}</version>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>${httpclient.version}</version>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpmime</artifactId>
    <version>${httpclient.version}</version>
</dependency>

However I don't have access to anything org.apache.http related in my codebase unless I add the extra dependency myself.

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
</dependency>

Why is this? Isn't this the same as adding a dependency twice?

Upvotes: 5

Views: 12646

Answers (1)

jst
jst

Reputation: 1747

The artifacts are declared in the dependencyManagement section of the spring-boot-dependencies pom.

Meaning when you inherit from the spring boot starter, you can declare you want to use any of the dependencies managed by it. Notice you don't need to provide a version of the httpclient. This is because Spring has so nicely managed it for you, hence dependencyManagement. So it is not the same thing as declaring it twice.

More info here http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-maven-parent-pom

Upvotes: 6

Related Questions