2
votes

I have a multimodule ant+ivy project. Dependencies between projects are recorded in ivy.xml files.

When <ivy:retrieve> is invoked it will try to download all dependencies including local projects.

How can I exclude my local projects from retrieval ?

Or maybe it's somehow possible to use Filesystem resolver such that it will resolve to ${projects.dir}/*/ivy.xml, kind of like IvyDE does with workspace resolver.

UPDATE

I want to exclude only local projects, but still retrieve their transitive dependencies. I need to duplicate behavior of IvyDE workspace resolver but outside of eclipse.

EXAMPLE

Given project structure:

  • projects/
    • local.module1/
      • bin/
      • lib/
      • build.xml
      • ivy.xml
        • <dependency org="local" name="local.module2" />
    • local.module2/
      • bin/
      • lib/
      • build.xml
      • ivy.xml
        • <dependency org="external" name="library1" />
    • common.xml
    • build.xml

I want local.module1 to be able to retrieve all it's transitive dependencies (local.module2, external.library1) except local projects (local.module2), so effectively this leaves external.library1.

From this I want to construct build classpath that consists of direct references to local projects and jar references to external libraries. In case of module1:

  • ../local.module2/bin
  • lib/external.library1-1.0.jar

In case anyone wonders why - I'm trying to fit ivy into existing build system with minimal changes.

2
David W. answer will address the question posed.... but I wonder if your problem is a bit deeper... Just in case it is, I would suggest learning about ivy's configuration mechanism for controlling groups of dependencies. If the build artifacts produced locally are part of a "local" configuration it is then trivial to separate them (ivy retrieve task supports configurations). In conclusion configurations are confusing at first but massively powerful.Mark O'Connor
I've tried moving local projects to different configuration but it excluded them completely with their transitive dependencies.Marcin Wisnicki
Very difficult to comment without a concrete example...Mark O'Connor
I've added an example.Marcin Wisnicki
Multi-module builds are not fun (in ANT or Maven)... before digging in does each module publish it's jar into a repository? See the following for an explanation (and doco links): stackoverflow.com/questions/4106143/…Mark O'Connor

2 Answers

0
votes

In your ivy.xml file, add exclude entities.

<dependency org="com.vegicorp"   name="flubaster"    
    conf="compile->default"   rev="3.3">
    <exclude org="com.local"/>
</dependency

This will prevent you from downloading anything from 'com.local' or whatever you called your organization when storing your local jars.

(Unless you're talking about the jars for this particular project, and if that's the case, they shouldn't be in your ivy.xml file at all).

0
votes

I have recently faced the same problem of partial ivy integration into legacy project just for fetching some transitive dependencies from the maven world while retaining existing build process with ant. Also had to avoid project modules publishing with ivy by using fake local filesystem resolver resolving to dummy jar.

ivysettings.xml

<ivysettings>
    <settings defaultResolver="default">
        <property name="local.maven2.dir" value="${user.home}/.m2/repository/" override="false"/>
        <property name="local-project.cache.dir" value="${ivy.settings.dir}/cache" override="false"/>
    </settings>
    <caches resolutionCacheDir="${local-project.cache.dir}" lockStrategy="artifact-lock" useOrigin="true">
        <cache name="local-project" basedir="${local-project.cache.dir}" useOrigin="true"/>
    </caches>
    <resolvers>
        <chain name="default">
            <filesystem name="local-maven-2" m2compatible="true" checkmodified="true" changingPattern=".*SNAPSHOT">
                <artifact pattern="${local.maven2.dir}/[organisation]/[module]/[revision]/[module]-[revision].[ext]"/>
                <ivy pattern="${local.maven2.dir}/[organisation]/[module]/[revision]/[module]-[revision].pom"/>
            </filesystem>
            <ibiblio name="central" m2compatible="true"
                     root="http://repo1.maven.org/maven2/"/>
        </chain>
        <filesystem name="local-project" force="true" checkmodified="true" changingPattern=".*" cache="local-project">
            <artifact pattern="${ivy.settings.dir}/dummy.jar"/>
            <ivy pattern="${ivy.settings.dir}/[module]-ivy.xml"/>
        </filesystem>
    </resolvers>
    <modules>
        <module organisation="example.com" resolver="local-project"/>
    </modules>
</ivysettings>

Had to exclude dummy jars from ant as failed to find better approach with ivy:

    <ivy:retrieve pattern="${dependency.export.dir}/[conf]/[artifact](-[revision]).[ext]" type="jar,bundle"/>
    <delete>
        <fileset dir="${dependency.export.dir}">
            <include name="**/*@local-project.jar"/>
        </fileset>
    </delete>

Still struggling to find a convenient way to exclude provided dependencies with ivy.

If someone interested in sample project source, it can be found in IVY-1443 bug attachment.