Bhaskar
Bhaskar

Reputation: 337

Multiple spring dependencies of different versions

I am working with spring-boot and want to include two different versions of spring-web in my project since one of the APIs in the latest version has been deprecated. In order to continue using that, I have included two dependencies of spring-web with different versions but eclipse is recognizing only of them.

I have tried excluding almost everything from the older version of spring-web but that doesn't seems to work either- any way out please?

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.0.2.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>aopalliance</groupId>
                <artifactId>aopalliance</artifactId>
            </exclusion>
            <exclusion>
                <groupId>axis</groupId>
                <artifactId>axis</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.caucho</groupId>
                <artifactId>com.springsource.com.caucho</artifactId>
            </exclusion>
            <exclusion>
                <groupId>commons-fileupload</groupId>
                <artifactId>commons-fileupload</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.el</groupId>
                <artifactId>el-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.faces</groupId>
                <artifactId>jsf-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.xml</groupId>
                <artifactId>jaxrpc-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.xml.ws</groupId>
                <artifactId>jaxws-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-mapper-asl</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-oxm</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.portlet</groupId>
                <artifactId>portlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

Upvotes: 1

Views: 4487

Answers (1)

FrVaBe
FrVaBe

Reputation: 49341

You won't be able to have two different versions of a dependency in your project because of a Maven concept called 'Dependency Mediation'. Have a look at the Maven Introduction to the Dependency Mechanism documentation.

Dependency mediation - this determines what version of a dependency will be used when multiple versions of an artifact are encountered. Currently, Maven 2.0 only supports using the "nearest definition" which means that it will use the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM. Note that if two dependency versions are at the same depth in the dependency tree, until Maven 2.0.8 it was not defined which one would win, but since Maven 2.0.9 it's the order in the declaration that counts: the first declaration wins.

Upvotes: 1

Related Questions