Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluded artifact shows in dependency:tree

Tags:

java

maven

My project depends on org.apache.pig:pig but I don't want the transitive dependencies of org.mortbay.jetty:jetty and org.mortbay.jetty:servlet-api. I added these two artifacts as <excludes> but that doesn't seem to work:

mvn dependency:tree -Dincludes=org.mortbay.jetty:servlet-api
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - myGroupp:myArtifact:jar:1.0-SNAPSHOT
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] myGroupp:myArtifact:jar:1.0-SNAPSHOT
[INFO] \- org.apache.pig:pig:jar:0.10.0:compile
[INFO]    \- org.mortbay.jetty:jetty:jar:6.1.26:compile
[INFO]       \- org.mortbay.jetty:servlet-api:jar:2.5-20081211:compile

Simple showcase 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>myGroupp</groupId>
  <artifactId>myArtifact</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <dependencies>
    <dependency>
      <groupId>org.apache.pig</groupId>
      <artifactId>pig</artifactId>
      <version>0.10.0</version>
      <exclusions>
        <exclusion>
          <artifactId>org.mortbay.jetty</artifactId>
          <groupId>jetty</groupId>
        </exclusion>
        <exclusion>
          <artifactId>org.mortbay.jetty</artifactId>
          <groupId>servlet-api</groupId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
</project>

I've tried this with: mvn --version

  • Apache Maven 2.2.1 (rdebian-8)
  • Apache Maven 3.0.4 (r1232337; 2012-01-17 00:44:56-0800)

Can someone help me exclude this?

like image 321
Steve Armstrong Avatar asked Feb 07 '13 23:02

Steve Armstrong


People also ask

What is exclusion in dependency?

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 exclude a specific version of a dependency in Maven?

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.


1 Answers

You have artifactId and groupId element values transposed.

Try these exclusions instead:

<exclusions>
  <exclusion>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty</artifactId>
  </exclusion>
  <exclusion>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>servlet-api</artifactId>
  </exclusion>
</exclusions>
like image 114
Brent Worden Avatar answered Oct 03 '22 02:10

Brent Worden