Excluding an Ivy dependency conditionally
<p>I need to build a custom Ant script that builds a project based on CI output. We use Atlassian Bamboo as CI server.</p>

<p>Normally our projects have a dependency to our platform module, managed via Ivy/Artifactory.</p>

<p>Our typical <code>dependencies.xml</code> file contains a dependency to <em>that</em> module, transitively. <strong>And</strong> other potential dependencies. As an example, our core module depends on lots of Spring packages, but not on Spring Boot. If a project needs Spring Boot too, it will define its dependency in its <code>dependencies.xml</code> file along with <code>&lt;depencency org="com.acme" name="core-platform"...</code></p>

<p>My goal now is to exclude <code>com.acme#core-platform</code> from resolution, because I am making a different task that uses Bamboo output artifact to take the latest build of the core module and its dependencies <strong>without</strong> going through Artifactory.</p>

<p>This is very important because during a build I may like to change the version of a dependent package (e.g. upgrade Spring 4.3.1 to 4.3.3) and test with the proper Spring. If I simply resolve dependencies to <code>com.acme#core-platform#latest.release</code>, which is released on Artifactory, I won't take 4.3.3 of Spring which was committed to Git and available in <code>core-platform</code>'s currently-building <code>dependencies.xml</code>. I hope my explanation is easy to understand.</p>

<p>So let's say I have this dependency list as an example</p>

<pre><code>    com.acme#core-platform#${version}
    org.hibernate#hibernate-java8#5.1.0.Final
    org.springframework.boot#spring-boot-starter-web#1.3.1.RELEASE
    commons-collections#commons-collections#3.2.2
    .... others
</code></pre>

<p>Full dependency is</p>

<pre><code>&lt;dependencies&gt;  
    &lt;dependency org="com.acme"              name="core-platform"          rev="${version}"         transitive="true"      conf="runtime-&gt;runtime" changing="true"/&gt;
    &lt;dependency org="com.acme"              name="core-platform"          rev="${version}"         transitive="true"      conf="compile-&gt;compile" changing="true"/&gt;
    &lt;dependency org="com.acme"              name="core-platform"          rev="${version}"         transitive="true"      conf="provided-&gt;provided" changing="true"/&gt;
    &lt;dependency org="com.acme"              name="core-platform"          rev="${version}"         transitive="true"      conf="junit-&gt;junit" changing="true"/&gt;
    &lt;dependency org="com.acme"              name="core-platform"          rev="${version}"         transitive="true"      conf="test-&gt;test" changing="true"/&gt;



    &lt;!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-java8 --&gt;
    &lt;dependency org="org.hibernate" name="hibernate-java8" rev="5.1.0.Final" transitive="false" /&gt;


    &lt;dependency org="org.springframework.boot"  name="spring-boot-starter-web"          rev="1.3.1.RELEASE"                 transitive="false" /&gt;
    &lt;dependency org="org.springframework.boot"  name="spring-boot-starter-tomcat"       rev="1.3.1.RELEASE"                 transitive="false" /&gt;
    &lt;dependency org="org.springframework.boot"  name="spring-boot-starter-validation"   rev="1.3.1.RELEASE"                 transitive="false" /&gt;


    &lt;dependency org="commons-collections"               name="commons-collections"              rev="3.2.2"             transitive="false" /&gt;


    &lt;!-- jackson2 libs --&gt;
    &lt;dependency org="com.fasterxml.jackson.datatype"    name="jackson-datatype-jdk8"            rev="2.8.1"             transitive="false"          conf="runtime-&gt;*"/&gt;
    &lt;dependency org="com.fasterxml.jackson.datatype"    name="jackson-datatype-jsr310"          rev="2.8.1"             transitive="false"          conf="runtime-&gt;*"/&gt;


    &lt;exclude module="joda-time" /&gt;
    &lt;exclude module="jackson-datatype-joda" /&gt;
&lt;/dependencies&gt;
</code></pre>

<p>I simply want to take Hibernates' Java8, commons-collections, etc.</p>

<ol>
<li>Creating a duplicate dependencies.xml is <strong>not</strong> an option</li>
<li>I was considering manipulating the dependencies.xml via Ant and have it exclude the <code>acme</code> modules by regex. Feasible but tricky</li>
<li>Unfortunately I can't combine Ant task's <code>ivy:retrieve</code> with attributes <code>file</code> and element <code>exclude</code>, because that would have helped a looooooot</li>
</ol>

<p>Any ideas?</p>