开发者

Keep Ivy from including test dependencies

开发者 https://www.devze.com 2023-02-24 08:34 出处:网络
Consider an ivy.xml like the following: <ivy-module version=\"2.0\"> <info organisation=\"com.foo\" module=\"FooBar\" />

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" />
      开发者_JAVA百科      <!--...-->
        </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."


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消