Search code examples
javaantivy

ivy:retrieve select which ivy.xml file to use


Is there a way to select which ivy.xml file to use when I invoke ivy:retrieve ?

Looking at the documentation it appears that I can use the settingsRef property to select which IVY settings file to use but it's not the ivysettings.xml file I wish to modify, rather it's ivy.xml. My use case is the following:

  • I have a main ivy.xml file that I use to fetch my compile-time and run-time dependencies
  • I also have a number of build tool-chain dependencies, i.e. jars used by certain Ant tasks themselves (e.g. stuff like findbugs, cobertura, pmd, code style compliance checking etc.). That's stuff that's neither a compile time nor a run-time dependency of my code. Moreover, it's the same in all the projects I am building with this tool chain so I'd like to be able to identify these dependencies in a single, separate ivy.xml file that I can simply copy across my projects.

Solution

  • So this is how I did it in the end:

    <target name="fetch-buildsystem-deps" depends="configure-ivy-settings">
        <ivy:resolve file="ivy-buildsystem.xml"/>
        <ivy:retrieve conf="build-system"
                      pattern="${lib-ivy-buildsystem.dir}/[artifact]-[revision](-[classifier]).[ext]"
                      sync="true"
                      type="jar, bundle"/>
    </target>
    

    … where the file ivy-buildsystem.xml identifies only the dependencies of my Ivy tasks. E.g. contains stuff like:

    <configurations>
        <conf name="build-system"  description="artifacts needed by the build-system itself"/>
    </configurations>
    <dependencies>
        <!--dependency org="ant-contrib" name="ant-contrib" rev="1.0b3" conf="build-system->master"/-->
        <dependency org="com.puppycrawl.tools"     name="checkstyle"   rev="5.9"   conf="build-system->default"/>
        <dependency org="com.google.code.findbugs" name="findbugs-ant" rev="3.0.0" conf="build-system->default"/>
        <dependency org="net.sourceforge.pmd"      name="pmd-java"     rev="5.5.3" conf="build-system->default"/>
    
    </dependencies>