Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 698
Alexander Zacharuk Avatar asked Jun 02 '15 22:06

Alexander Zacharuk


1 Answers

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

like image 160
jst Avatar answered Oct 23 '22 08:10

jst