Maven 正在选择旧版本的依赖项 [英] Maven is picking dependency of old version

查看:52
本文介绍了Maven 正在选择旧版本的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试集成 Maven - Spring MVC - Rest,但我面临的问题是 maven 没有选择spring-web/aop/beans/context/core"(版本 4.3.12)依赖项.

I am trying to integrate Maven - Spring MVC - Rest , but i am facing issue in which maven is not picking "spring-web/aop/beans/context/core"(version 4.3.12) dependency .

maven 选择了spring-web/aop/beans/context/core" 2.5.6.SEC03 依赖项,而不是 spring-web/aop/beans/context/core 4.3.12.RELEASE.因为这个org.springframework.web.bind.annotation.RequestMapping;"没有得到解决,因为它在 spring web 2.5.6.SEC03 中不存在

Instead of spring-web/aop/beans/context/core 4.3.12.RELEASE , maven is picking "spring-web/aop/beans/context/core" 2.5.6.SEC03 dependency. because of this "org.springframework.web.bind.annotation.RequestMapping;" is not getting resolve as it is not there in spring web 2.5.6.SEC03

Maven 版本 -> apache-maven-3.5.2

Maven Version -> apache-maven-3.5.2

Maven 环境变量

pom.xml

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

    <groupId>org.portal</groupId>
    <artifactId>HumanResourcePortal</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <warName>${project.artifactId}-${project.version}</warName>
                    <outputDirectory>${project.basedir}/target</outputDirectory>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>2.6.1</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>
                                /home/shivam/apache-tomcat-7.0.81/webapps/${project.artifactId}-${project.version}
                            </directory>
                        </fileset>
                        <fileset>
                            <directory>
                                /home/shivam/apache-tomcat-7.0.81/webapps
                            </directory>
                            <includes>
                                <include>
                                    ${project.artifactId}-${project.version}.{packaging}
                                </include>
                            </includes>
                       </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>/home/shivam/apache-tomcat-7.0.81/webapps</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}/target</directory>
                                    <includes>
                                        <include>${project.artifactId}-${project.version}.${packaging}</include>
                                        <include>${project.artifactId}-${project.version}</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.3.12.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.12.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>4.3.12.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.3.12.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.3.12.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>4.3.12.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>1.4.9</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-bundle</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-core</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>jersey-spring</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.11.Final</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.12</version>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.1.0.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.3.12.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.3.12.RELEASE</version>
        </dependency>
    </dependencies>
</project>

运行maven依赖树之后

after Running maven dependency tree

运行mvn help:effectivePom"后

after running "mvn help:effectivePom"

推荐答案

最有可能的是,过时的 Spring 版本来自 jersey-spring 瞬态依赖.尝试使用最新版本之一.

Most probably, that outdated Spring version comes from jersey-spring transient dependencies. Try to use one of the latest versions.

更好的选择?

嗯,首先,你可以使用 部分.它用于锁定整个项目中依赖项的版本. 将适用于任何工件.

Well, first of all, you can use <dependencyManagement> section. It is used to lock the versions of the dependencies across the project. <dependencyManagement> will work with any artifacts.

第二,从 3.x 版本开始 Spring提供物料清单.BOM 是 Maven 中的一个特殊概念,类似于 ,但它允许通过一个 BOM 导入锁定多个依赖项.为一些流行的库(例如 Spring 或 Camel)准备和发布 BOM.

Second, starting somewhere from 3.x releases Spring provides a Bill of Materials. BOM is a special concept in Maven, like a <dependencyManagement>, but it allows to lock multiple dependencies with one BOM import. BOMs are prepared and published for some popular libraries, like Spring or Camel.

这篇关于Maven 正在选择旧版本的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆