简体   繁体   English

如何排除旧版本的 maven 依赖并使用它的新版本?

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

I am working with Maven project and I have two projects, ProjectA and ProjectB .我正在使用 Maven 项目,我有两个项目ProjectAProjectB My ProjectA is a maven library whose pom looks like this:我的ProjectA是一个 maven 库,其 pom 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.texture.partial</groupId>
        <artifactId>PartialPlatform</artifactId>
        <version>2.1.5-RELEASE</version>
    </parent>

    <groupId>com.texture.transform.golden</groupId>
    <artifactId>SampleClient</artifactId>
    <version>1.0.4</version>

    <dependencies>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>com.texture.partial.core</groupId>
            <artifactId>PartialKernel</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.webres</groupId>
            <artifactId>WebResPartial</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.texture.kernel</groupId>
            <artifactId>TextureServer</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.kernel</groupId>
            <artifactId>Kernel</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.v3jars.Houston</groupId>
            <artifactId>KernelDAL</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.kernel</groupId>
            <artifactId>uKernel</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.kernel</groupId>
            <artifactId>uKernelCore</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-asm</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.cglib</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.partial.core</groupId>
            <artifactId>ConfigWeb</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.partial.core</groupId>
            <artifactId>PartialWeb</artifactId>
        </dependency>
        <dependency>
            <groupId>com.googlecode.jmockit</groupId>
            <artifactId>jmockit</artifactId>
            <version>1.7</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>-javaagent:"${settings.localRepository}"/com/googlecode/jmockit/jmockit/1.7/jmockit-1.7.jar</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <configuration>
                    <instrumentation>
                        <excludes>
                            <exclude>**/test/**/*.class</exclude>
                        </excludes>
                    </instrumentation>
                    <formats>
                        <format>xml</format>
                        <format>html</format>
                    </formats>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

In my above pom, PartialKernel is bringing older version of various Spring Framework dependencies like spring-core , spring-web .在我上面的 pom 中, PartialKernel带来了各种 Spring Framework 依赖项的旧版本,例如spring-corespring-web It is bringing 3.2.8.RELEASE version and I want to use latest version of those two spring framework, which is 4.1.6.RELEASE .它带来了3.2.8.RELEASE版本,我想使用这两个 spring 框架的最新版本,即4.1.6.RELEASE What is the right way to exclude older versions of spring-core and spring-web coming from PartialKernel and use latest version?排除来自PartialKernel旧版本spring-corespring-web并使用最新版本的正确方法是什么?

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>

I need to use latest version since some classes are there in latest version only.我需要使用最新版本,因为某些类仅在最新版本中存在。

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.如果您愿意承担这个风险,您可以使用 maven exclusions来忽略传递依赖。

You can exclude, for example, spring-core from being brought in by PartialKernel by adding:例如,您可以通过添加以下内容来排除PartialKernel引入的spring-core

<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.请注意,您必须为每个引入 spring 依赖项的依赖项执行此操作。

Now define the version of spring-core you want to use in the top level pom dependency management section:现在在顶级 pom 依赖管理部分定义要使用的spring-core版本:

<dependencyManagement>
  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>
   </dependencies>
</dependencyManagement>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 强制maven spring boot项目使用旧版本的依赖项而不是其他依赖项的新版本 - Forcing maven spring boot project to use older version of a dependency instead of a new version from another dependency 如何使用旧版 Maven? - How to use older version of Maven? Java / Maven如何使用使用项目中已使用的另一个依赖项的旧版本的依赖项 - Java/Maven how to use a dependency that uses an older version of another dependency that is already used in the project Maven:将相同工件的旧版本添加为依赖项 - Maven: Add older version of the same artifact as dependency Maven 依赖与较旧的 Spring Boot 版本 - Maven dependency with older spring boot version 如果在父项目中存在较新版本,如何排除maven依赖项 - How to exclude a maven dependency if in the parent project exists a newer version of it 使用Maven版本插件处理依赖版本 - Using maven versions plugin to handle dependency version 如何在NetBeans 8上使用Maven项目的旧版Java(不是默认版本) - How to use older version of Java (not the default) with Maven project on NetBeans 8 如何使用maven程序集插件从依赖jar中排除一个包? - How to use maven assembly plugin to exclude a package from dependency jar? 如何在maven中排除嵌套依赖项 - How to exclude nested dependency in maven
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM