简体   繁体   English

Maven 依赖排除似乎不起作用

[英]Maven dependency exclusion doesn't seem to work

I have a Maven project depending on couple other Maven projects.我有一个 Maven 项目,取决于其他几个 Maven 项目。 I am using Spring 3.1.1 in my project and dependent projects have 3.0.6.我在我的项目中使用 Spring 3.1.1,依赖项目有 3.0.6。 I am trying to exclude Spring 3.0.6 when deploying since having both isn't possible.我试图在部署时排除 Spring 3.0.6,因为两者都是不可能的。 I have added an explicit exclusion in my POM for that but for some reason I still see old version of spring core jars in the WEB-INF/lib folder when I start the Tomcat server.为此,我在 POM 中添加了显式排除项,但由于某种原因,当我启动 Tomcat 服务器时,我仍然在WEB-INF/lib文件夹中看到旧版本的 spring 核心 jar。 Can someone point me out where I am going wrong.有人可以指出我哪里出错了。 Here is my pom.xml :这是我的pom.xml

<project>
   ....
<properties>
    <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
</properties>
<dependency> 
        <groupId>com.test.abc</groupId> 
        <artifactId>abc</artifactId>
         <version>1.0</version>
         <type>war</type>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
             </exclusion>
        </exclusions>            
      </dependency> 
          <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework-version}</version>
        <exclusions>
            <!-- Exclude Commons Logging in favor of SLF4j -->
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
             </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>3.0.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-xml</artifactId>
        <version>1.0-m2</version>
    </dependency>
        ....    
       </project>

Your dependency type is war so there is no resolution happening here.你的依赖类型是战争,所以这里没有解决方案。 Maven overlays the war contents over your project. Maven 将战争内容覆盖在您的项目上。

When the war is published to repository, the artifact will contain dependent libraries in WEB-INF lib folder.当战争发布到存储库时,工件将在 WEB-INF lib 文件夹中包含依赖库。 During overlay it does not treat lib folder any different from any static resource unless you tell it to exclude in different way.Check 'overlay' property here在覆盖期间,它不会将 lib 文件夹与任何静态资源区别对待,除非您告诉它以不同的方式排除。在 此处检查“覆盖”属性

In my case I thought I excluded the right dependency.就我而言,我认为我排除了正确的依赖项。 With eclipse, on dependency hierarchy tab you can right click on it and click exclude artifact and it excluded the right dependency (they both had the same artifactId but different groupId)使用 eclipse,在依赖层次结构选项卡上,您可以右键单击它并单击排除工件,它排除了正确的依赖项(它们都具有相同的 artifactId 但不同的 groupId)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM