How to exclude older versions of maven dependency and use new version of it?

前端 未结 1 650
清歌不尽
清歌不尽 2020-12-19 03:34

I am working with Maven project and I have two projects, ProjectA and ProjectB. My ProjectA is a maven library whose pom looks like th

相关标签:
1条回答
  • 2020-12-19 04:13

    There may be incompatible differences between the version of a library that a dependency requires and the one you want to use. If you are happy to take this risk, you can use maven exclusions to ignore transitive dependencies.

    You can exclude, for example, spring-core from being brought in by PartialKernel by adding:

    <dependency>
        <groupId>com.texture.partial.core</groupId>
        <artifactId>PartialKernel</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    

    Note that you will have to do this for every dependency that brings in spring dependencies.

    Now define the version of spring-core you want to use in the top level pom dependency management section:

    <dependencyManagement>
      <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.1.6.RELEASE</version>
        </dependency>
       </dependencies>
    </dependencyManagement>
    
    0 讨论(0)
提交回复
热议问题