How to exclude transitive dependency in ant build using maven task for ant?

2.9k views Asked by At

How to exclude transitive dependency in maven task for ant. Scope: runtime and provided doesn't seem to be of any help in this case. This is my build.xml

<artifact:remoteRepository url="https://mynexus/" id="remote.repository"/>

<artifact:dependencies filesetId="dependency.fileset" useScope="runtime">
     <dependency version="1.7.0" artifactId="commons-beanutils" groupId="commons-beanutils"/>
</artifact:dependencies>

commons-beanutils has dependency commons-logging that I need to exclude.

2

There are 2 answers

2
William Leung On BEST ANSWER

maven-ant supports this exclusion, please RTFM https://maven.apache.org/ant-tasks/reference.html#exclusion

just as

<artifact:dependencies filesetId="dependency.fileset" useScope="runtime">
  <artifact:dependency version="1.7.0" artifactId="commons-beanutils" groupId="commons-beanutils">
    <exclusion groupId="commons-logging" artifactId="commons-logging">
  </<artifact:dependency>
</artifact:dependencies>

But I didn't find any supports for exclude some dependencies defined by a pom file

2
Mark O'Connor On

I don't think the Maven task supports this feature. Have you considered using Apache ivy instead? The following 2 examples demonstrates the exclusion capability.

The cachepath task is useful for managing classpaths:

<ivy:cachepath pathid="compile.path">
  <dependency org="commons-beanutils" name="commons-beanutils" rev="1.7.0" conf="default">
    <exclude module="commons-logging"/>
  </dependency>
</ivy:cachepath>

The retrieve task can be used to download and save files locally:

<ivy:retrieve pattern="lib/[artifact]-[revision](-[classifier]).[ext]">
  <dependency org="commons-beanutils" name="commons-beanutils" rev="1.7.0" conf="default">
    <exclude module="commons-logging"/>
  </dependency>
</ivy:retrieve>