Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven dependency exclusion doesn't seem to work

Tags:

maven

I have a Maven project depending on couple other Maven projects. I am using Spring 3.1.1 in my project and dependent projects have 3.0.6. I am trying to exclude Spring 3.0.6 when deploying since having both isn't possible. 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. Can someone point me out where I am going wrong. Here is my 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>
like image 629
sri Avatar asked Feb 22 '13 17:02

sri


People also ask

How you can exclude dependency in Maven?

Exclude a dependency You can use a diagram to exclude a dependency from the project's POM. Select a dependency in the diagram window. From the context menu, choose Exclude. From the list, select the module (if any) where the exclusion definition will be added.

How does Maven exclusion work?

Exclusions are set on a specific dependency in your POM, and are targeted at a specific groupId and artifactId. When you build your project, that artifact will not be added to your project's classpath by way of the dependency in which the exclusion was declared.

How do I fix Maven dependency issues?

If the dependencies weren't imported correctly (IntelliJ IDEA highlights them), try to perform the following actions: You can check your local maven repository in the Maven | Repositories settings and try to update it. You can check the jar file of the local . m2 repository to see if it was downloaded correctly.

How do I exclude a dependency from all?

Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.


2 Answers

Your dependency type is war so there is no resolution happening here. Maven overlays the war contents over your project.

When the war is published to repository, the artifact will contain dependent libraries in WEB-INF lib folder. 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

like image 74
Adisesha Avatar answered Nov 10 '22 23:11

Adisesha


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)

like image 34
Tudor Avatar answered Nov 10 '22 23:11

Tudor