tags:

views:

459

answers:

2

I have a fairly large ivy.xml containing a number of configurations which are the same for a number of projects.

I would like to break out this large repetitive section in to a common include file. Somehow I can't find any documentation describing that this can be done.

Anyone who has an idea whether this is doable?

EDIT: After some further thinking, I think this is not doable on purpose. An Ivy file is meant to be one cohesive unit and should contain no file based references, only references to other ivy modules...

A: 

If you are using ivy from ant and you are running Ant 1.6 or later, you could use the <import> task to include build file fragments within your ant build file. The referenced files have to be complete Ant build files, though:

<?xml version="1.0"?>
<project name="my-project" default="usage" basedir=".">
  <target name="setup">
    ...
  </target>

  <import file="./common.xml"/>
  ...
</project>

You could also use standard XML syntax from within your ivy.xml or build.xml file:

<?xml version="1.0"?>
<!DOCTYPE project [
       <!ENTITY common SYSTEM "common.xml">
]>
<project name="my-project" default="usage" basedir=".">
  <target name="setup">
    ...
  </target>

  &common;
  ...    
</project>

This will literally include the contents of common.xml where you've placed the &common; entity.

(The filename common.xml in this example is resolved relative to the containing XML file by the XML parser. You may also use an absolute file: protocol URI.)

Tom
+3  A: 

You could create an ivy meta-module, which depends upon all of those common packages, and then have all your other projects resolve the common libraries through transitive dependency:

    <?xml version="1.0"?>
    <ivy-module version="2.0">
        <info organisation="com.example" module="common-libs"/>
          <configurations>
            <conf name="runtime" transitive="true" visibility="public" />
            <conf name="master" transitive="true" visibility="public" />
            <conf name="compile" transitive="true" visibility="public" />
            <conf name="default" transitive="true" visibility="public" extends="master" />
          </configurations>
          <dependencies>
                <dependency org="oracle" name="ojdbc14_g" rev="10.2.0.3"
 conf="compile->compile(*),master(*);runtime->runtime(*);master->master(*)"/>
                <dependency org="tomcat" name="servlet-api" rev="6.0.16" 
 conf="compile->compile(*),master(*);runtime->runtime(*);master->master(*)"/>
                <dependency org="junit" name="junit" rev="4.3"
 conf="compile->compile(*),master(*);runtime->runtime(*);master->master(*)"/>
          </dependencies>
    </ivy-module>

And for a typical project:

<?xml version="1.0"?>
    <ivy-module version="2.0">
    <info organisation="com.example" module="myproject"/>
      <configurations>
        <conf name="runtime" transitive="true" visibility="public" />
        <conf name="master" transitive="true" visibility="public" extends="runtime"/>
        <conf name="compile" transitive="true" visibility="public" />
        <conf name="default" transitive="true" visibility="public" extends="master" />
      </configurations>
      <dependencies>
        <dependency org="com.example" name="common-libs" rev="latest.release" 
          conf="compile->compile(*),master(*);runtime->runtime(*);master->master(*)"/>
      </dependencies>
    </ivy-module>

Here I'm using the traditional configuration naming conventions from the POM->Ivy translations of the Maven resolver, though you could map the configuration names in any way that made sense to you. I tend to use the ivy:install task to copy Maven modules into our Ivy repository, so I use the default ivy.xmls for the most part. If you're using IvyRoundup, you'll primarily want to map the "default" configuration transitively.

Kirby Files