1

I am using Maven 3.0.3 and a certain plugin that includes a redundant dependency in its pom.xml that I want to exclude. The classes in this redundant jar are now included in some other artifact that is indeed in the the classpath of the project build so there won't be any build runtime issues.

Is there a way to exclude a plugin's dependency from being added to the classpath of the plugin at build time?

shlomi33
  • 1,458
  • 8
  • 9
  • Plugin dependencies are normally not added to the build classpath. Are you sure this is happening? Can you give an example? What does `mvn dependency:tree` say? – lexicore Nov 21 '16 at 08:15
  • What i did that did work (and was just to try and understand the problem) is to remove the dependency from the plugin's pom.xml (in my .m2). So I am not sure that the jar is not in the classpath of the plugin execution. – shlomi33 Nov 21 '16 at 08:36
  • A simple search on "maven plugin dependency exclusion" yields this SO question as the first result: http://stackoverflow.com/questions/6028534/how-to-exclude-dependency-in-a-maven-plugin – walen Nov 21 '16 at 08:45
  • Yep, saw it... Does not work... – shlomi33 Nov 21 '16 at 08:54
  • That isn't possible in the general case, but maybe if you give more info, we can find a workaround. What dependency are you trying to exclude? From which plugin? Can you give some examples? – Tunaki Nov 21 '16 at 08:59
  • @Tunaki, specifically i am trying to remove the xerces jar from the xml-maven-plugin – shlomi33 Nov 21 '16 at 09:07
  • 1
    @shlomi33 I guess you [need to wait for a release](https://github.com/mojohaus/xml-maven-plugin/commit/0fe8231164e08c0d73e770177904d27ff1490eca) :), or build it yourself. – Tunaki Nov 21 '16 at 09:11
  • @Tunaki, thanks! But what is the reason that Maven prevents the user from removing a plugin dependency? Do you have any idea? – shlomi33 Nov 21 '16 at 09:15
  • 1
    There are several issues on JIRA for this usecase, see [MNG-2163](https://issues.apache.org/jira/browse/MNG-2163), and its duplicates ([MNG-2969](https://issues.apache.org/jira/browse/MNG-2969) and [MNG-2448](https://issues.apache.org/jira/browse/MNG-2448)) -- they were closed due to no activity though. – Tunaki Nov 21 '16 at 09:19
  • @schlomi33 You did not answer questions in my comment. – lexicore Nov 21 '16 at 09:48
  • @lexicore, ohhh, sorry about that... seems lime Tunaki has answered my question. as for your question, the jar is of course not in the dependency:tree as it is not a dependency of the project (or any transitive dependency) but a dependency of some plugin i am using during the build. – shlomi33 Nov 21 '16 at 11:14
  • You should stop using Maven 3.0.3 cause it has many bugs...Upgrade to a newer one like Maven 3.3.9... – khmarbaise Nov 21 '16 at 16:51

1 Answers1

1

You can use an <exclusions> tag in your dependency, in example :

<dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-java-sdk</artifactId>
  <version>1.10.0</version>
  <exclusions>
    <exclusion>
      <groupId>joda-time</groupId>
      <artifactId>joda-time</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Will exclude joda-time from aws-java-sdk transitive dependencies.

Simon Oualid
  • 365
  • 2
  • 9
  • this is a regular dependency exclusion. I need to exclude a plugin's specific dependency – shlomi33 Nov 21 '16 at 08:33
  • I am not sure to understand, but if you want to exclude all dependencies, you can use * as `groupId` and `artifactId` within `exclusion if you want to exclude all dependencies. I'll update the answer accordingly if that was your initial need. – Simon Oualid Nov 21 '16 at 08:40
  • 1
    i need to remove a dependency from a plugin dependency tree. the exclusion thingy is for "normal" dependencies. not for dependencies that come from a plugin – shlomi33 Nov 21 '16 at 08:58