问题
I'm using Ivy to manage my dependencies, with some problems on provided jars
This is my ivy.xml file
<configurations>
<conf name="local" visibility="private" />
<conf name="compile" description="used for building" />
<conf name="test" extends="compile" description="used for testing" />
<conf name="runtime" description="used for running" />
<conf name="master" description="used for publishing" />
<conf name="default" extends="master, runtime" />
</configurations>
<dependencies>
<dependency org="xalan" name="xalan" rev="2.7.1"/>
<dependency org="org.w3c.css" name="sac" rev="1.3"/>
<dependency org="com.lowagie" name="itext" rev="2.0.8">
<exclude org="bouncycastle"/>
</dependency>
<!--Provided-->
<dependency org="javax.ejb" name="ejb-api" rev="3.0" conf="compile"/>
<dependency org="javax.jms" name="jms-api" rev="1.1-rev-1" conf="compile"/>
</dependencies>
Ejb and jms are provided by the container
Affer execute I obtain
---------------------------------------------------------------------
| | modules || artifacts |
| conf | number| search|dwnlded|evicted|| number|dwnlded|
---------------------------------------------------------------------
| compile | 8 | 0 | 0 | 0 || 6 | 0 |
| default | 6 | 0 | 0 | 0 || 6 | 0 |
---------------------------------------------------------------------
So Ivy is getting fine the dependencies but when I execute this
<ivy:cachepath pathid="normal.classpath" />
<pathconvert property="expanded.normal.classpath" refid="normal.classpath"/>
<echo message="${expanded.normal.classpath}" file="normal.classpath.txt"/>
<ivy:cachepath conf="compile" pathid="compile.classpath" />
<pathconvert property="expanded.compile.classpath" refid="compile.classpath"/>
<echo message="${expanded.compile.classpath}" file="compile.classpath.txt"/>
Both classpath are the same. Anyone knows why?
回答1:
The first ivy:cachepath
has no conf defined, to it resolve all configurations, so every module is included.
The second ivy:cachepath
is requesting only the conf compile. So the dependencies which are declared as conf="compile"
(synonymous of conf="compile->compile"
) are obviously included. And the dependencies without any conf
attribute are also included, because the default conf is *->*
.
More documentation about configurations on dependencies:
- "Configurations mapping" in http://ant.apache.org/ivy/history/latest-milestone/ivyfile/dependency.html
defaultconf
attribute in http://ant.apache.org/ivy/history/latest-milestone/ivyfile/dependencies.html
回答2:
I'd recommend reducing the number of configurations and ensure each dependency has an explicit mapping.
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="compile" description="used for building"/>
<conf name="runtime" description="used for running" extends="compile"/>
<conf name="test" description="used for testing" extends="runtime"/>
</configurations>
<dependencies>
<!-- compile dependencies -->
<dependency org="javax.ejb" name="ejb-api" rev="3.0" conf="compile->default"/>
<dependency org="javax.jms" name="jms-api" rev="1.1-rev-1" conf="compile->default"/>
<!-- runtime dependencies -->
<dependency org="xalan" name="xalan" rev="2.7.1" conf="runtime->default"/>
<dependency org="org.w3c.css" name="sac" rev="1.3" conf="runtime->default"/>
<dependency org="com.lowagie" name="itext" rev="2.0.8" conf="runtime->default">
<exclude org="bouncycastle"/>
</dependency>
</dependencies>
</ivy-module>
This will produce the following output:
---------------------------------------------------------------------
| | modules || artifacts |
| conf | number| search|dwnlded|evicted|| number|dwnlded|
---------------------------------------------------------------------
| compile | 2 | 2 | 2 | 0 || 2 | 2 |
| runtime | 7 | 7 | 7 | 0 || 7 | 7 |
| test | 7 | 7 | 7 | 0 || 7 | 7 |
---------------------------------------------------------------------
Demonstrating how there are only 2 jars on you compile configuration (as expected) and how the test configuration is identical to runtime (expected because one extends the other). I find it rare to need more than these 3 distinct classpaths in an ANT build build.
Additional
I noticed in your report nothing was downloaded. The cleancache task is useful to run periodically and make sure your build is fresh.
The report ivy is also very useful to understand the transitive dependencies properly.
<project name="demo" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="resolve" description="Use ivy to resolve classpaths">
<ivy:resolve/>
<ivy:report todir='build/ivy' graph='false' xml='false'/>
<ivy:cachepath pathid="compile.path" conf="compile"/>
<ivy:cachepath pathid="test.path" conf="test"/>
</target>
<target name="clean">
<delete dir="build"/>
</target>
<target name="clean-all" depends="clean">
<ivy:cleancache/>
</target>
</project>
来源:https://stackoverflow.com/questions/16569534/apache-ivy-and-configurations