web-dev-qa-db-ja.com

古いバージョンのMaven依存関係を除外し、新しいバージョンを使用するにはどうすればよいですか?

私はMavenプロジェクトで作業しており、ProjectAProjectBの2つのプロジェクトがあります。私のProjectAは、pomが次のようになっているMavenライブラリです。

<?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>

上記のpomでは、PartialKernelは、spring-corespring-webなどのさまざまなSpringFramework依存関係の古いバージョンをもたらしています。 3.2.8.RELEASEバージョンが導入されており、これら2つのSpringFrameworkの最新バージョンである4.1.6.RELEASEを使用したいと思います。 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>

一部のクラスは最新バージョンのみであるため、最新バージョンを使用する必要があります。

9
john

依存関係に必要なライブラリのバージョンと使用するライブラリのバージョンには、互換性のない違いがある場合があります。このリスクを冒して満足している場合は、maven exclusionsを使用して推移的な依存関係を無視できます。

たとえば、次を追加することで、spring-corePartialKernelによる取り込みから除外できます。

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

Springの依存関係をもたらすすべての依存関係に対してこれを行う必要があることに注意してください。

次に、トップレベルのpomで使用するspring-coreのバージョンを定義します 依存関係管理 セクション:

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