0
votes

I want to download artifacts using ivy:resolve, but using a pattern that uses the [conf] attribute. So I have defined the following in IvySettings.xml

<caches defaultCacheDir="${env.IvyLib}\cache" artifactPattern="[conf]\[artifact].[ext]" checkUpToDate="false" />

Notice the pattern

artifactPattern="[conf]\[artifact].[ext]"
, so I want to resolve the dependencies and place them in a folder as per their configuration. I have defined the following configuration in Ivy.xml
<configurations>
    <conf name="ConfGroup1" description="First group of dependencies"/>
    <conf name="ConfGroup2" description="Second group of dependencies"/>
</configurations>
<dependencies>
    <dependency org="derby-db" name="derby-db" rev="10.2.2.0" conf="ConfGroup1->default">
        <artifact name="derby-db" type="zip" ext="zip" />
    </dependency>
    <dependency org="derby-db" name="derby-db" rev="10.4.1.3" conf="ConfGroup2->default">
        <artifact name="derby-db" type="zip" ext="zip" />
    </dependency>
</dependencies>

Now the dependencies get resolved fine, but only 1 folder gets created for configuration: default. No folder is being created for ConfGroup1 & ConfGroup2 configurations. How can I be able to create multiple folders as per my defined configurations during resolve?

P.S., I know this can be achieved using ivy:retrieve, but I do not want to use it, because it will involve copying artifacts from ivy cache to another place after ivy:resolve, and I have multi-gigabyte worth of artifacts. Copying them separately will create additional overhead during the build, which I cannot afford due to the project requirements.

1

1 Answers

1
votes

The ivy retrieve task has a symlinks option, that can be used to conserve space.

Example

├── build.xml
├── ivysettings.xml
├── ivy.xml
└── target
    ├── ivy-reports
    │   ├── ivy-report.css
    │   ├── myorg-mymod-ConfGroup1.html
    │   └── myorg-mymod-ConfGroup2.html
    └── lib
        ├── ConfGroup1
        │   └── db-derby-10.12.1.1.zip -> /home/mark/.ivy2/cache/db-derby/db-derby/zips/db-derby-10.12.1.1.zip
        └── ConfGroup2
            └── db-derby-10.11.1.1.zip -> /home/mark/.ivy2/cache/db-derby/db-derby/zips/db-derby-10.11.1.1.zip

build.xml

<project name="demo" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">

    <property name="build.dir" location="target"/>

    <target name="resolve">
        <ivy:resolve/>

        <ivy:report todir='${build.dir}/ivy-reports' graph='false' xml='false'/>

        <ivy:retrieve pattern='${build.dir}/lib/[conf]/[module]-[revision].[ext]' symlink="true"/>
    </target>

</project>

ivy.xml

<ivy-module version="2.0">
  <info organisation="myorg" module="mymod"/>

  <configurations>
    <conf name="ConfGroup1" description="First group of dependencies"/>
    <conf name="ConfGroup2" description="Second group of dependencies"/>
  </configurations>
  <dependencies>
    <dependency org="db-derby" name="db-derby" rev="10.12.1.1" conf="ConfGroup1->default">
        <artifact name="db-derby" type="zip" ext="zip" />
    </dependency>
    <dependency org="db-derby" name="db-derby" rev="10.11.1.1" conf="ConfGroup2->default">
        <artifact name="db-derby" type="zip" ext="zip" />
    </dependency>
  </dependencies>

</ivy-module>

ivysettings.xml

<ivysettings>
  <settings defaultResolver="central"/>
  <resolvers>
    <ibiblio name="central" m2compatible="true" />
    <url name="db-derby">
      <artifact pattern="http://ftp.heanet.ie/mirrors/www.apache.org/dist//db/derby/[module]-[revision]/[module]-[revision]-bin.[ext]"/>
    </url>
  </resolvers>
  <modules>
    <module organisation="db-derby" resolver="db-derby" />
  </modules>
</ivysettings>