Keep Ivy from including test dependencies
Asked Answered
C

1

5

Consider an ivy.xml like the following:

<ivy-module version="2.0">
    <info organisation="com.foo" module="FooBar" />
        <dependencies>
            <dependency org="net.sf.ehcache" name="ehcache-core" rev="2.2.0" />
            <!--...-->
        </dependencies>
    </info>
</ivy-module>

When I run Ivy, it fetches all dependencies for EHCache, even testing dependencies. Specifically, it tries to pull in Hibernate 3.5.1 (which, in the POM file, is listed as a "test" dependency).

How do I prevent Ivy from including test dependencies? I could list it as an excluded dependency, but I don't want to have to do this for every test dependency. I'm new to Ivy and used to the way Maven does things. I was reading about configurations but I don't understand how this aspect of Maven's "scope" maps to "configurations."

Codicil answered 12/4, 2011 at 18:46 Comment(0)
I
9

You need to define the configuration of the dependency like:

<dependency org="net.sf.ehcache" name="ehcache-core" rev="2.2.0" conf="compile"/>

If you omit conf it is assumed, that you meant conf ="*", which will download all configurations for that dependency.

Here is a simple Example:

<configurations>
    <conf name="test" visibility="public" />
    <conf name="compile" visibility="public" />
</configurations>
<publications>
    <artifact name="${project.name}" type="jar"  conf="compile" ext="jar"/>
    <artifact name="${project.name}-test" type="jar"  conf="test" ext="jar"/>
</publications>
<dependencies>
    <!-- COMPILE  -->
    <dependency org="log4j" name="log4j" rev="1.2.14" conf="compile->*"/>
    <dependency org="apache" name="commons-net" rev="2.0" conf="compile->*"/>
    <dependency org="itext" name="itext" rev="1.4.6" conf="compile->*"/>
    <dependency org="jsch" name="jsch" rev="0.1.29" conf="test->*"/>
    <!-- TEST --> 
</dependencies>

In this example jsch will be included in the test and the compile configuration.

If you resolve this dependency later with conf ="compile" you will get all dependencies EXCEPT jsch. If you resolve this dependency with conf ="test" you will get jsch only.

And if test would extend compile, you would get all jars.

<configurations>
    <conf name="test" visibility="public" extends="compile" />
    <conf name="compile" visibility="public" />
</configurations>
Inhibit answered 21/4, 2011 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.