短前面回答是使用常春藤配置:
http://ant.apache.org/ivy/history/latest-milestone/tutorial/conf.html
常春藤配置可用于为不同的目的组依赖关系。你不需要多个常春藤文件。
例
这里是我的决心,目标:
<target name="resolve" description="Download dependencies and setup classpaths">
<ivy:resolve/>
<ivy:report todir='${reports.dir}/ivy' graph='false' xml='false'/>
<ivy:cachepath pathid="compile.path" conf="compile"/>
<ivy:cachepath pathid="test.path" conf="test"/>
<ivy:cachepath pathid="build.path" conf="build"/>
</target>
然后可以在我需要一个类路径
<!-- Compiling code -->
<javac srcdir="${src.dir}"... classpathref="compile.path"/>
<!-- Testing code -->
<junit haltonfailure="yes" fork="true">
<classpath>
<path refid="test.path"/>
<pathelement path="${classes.dir}"/>
<pathelement path="${test.classes.dir}"/>
</classpath>
..
</junit>
<!-- 3rd party ANT tasks -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpathref="build.path"/>
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml" classpathref="build.path"/>
..
个人各种任务直接使用我只用检索任务建立档案。在这里,我再次使用,为了控制我想这瓶配置:
<ivy:retrieve pattern="${build.dir}/libs/[artifact].[ext]" conf="runtime"/>
<war destfile="${war.file}" webxml="${resources.dir}/web.xml">
<fileset dir="${resources.dir}" excludes="web.xml"/>
<classes dir="${build.dir}/classes"/>
<lib dir="${build.dir}/libs"/>
</war>
IVY文件
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="compile" description="Required to compile application"/>
<conf name="runtime" description="Additional run-time dependencies" extends="compile"/>
<conf name="test" description="Required for test only" extends="runtime"/>
<conf name="build" description="ANT task dependencies"/>
</configurations>
<dependencies>
<!-- compile dependencies -->
<dependency org="org.slf4j" name="slf4j-api" rev="1.7.5" conf="compile->default"/>
<!-- runtime dependencies -->
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.7.5" conf="runtime->default"/>
<!-- test dependencies -->
<dependency org="junit" name="junit" rev="4.11" conf="test->default"/>
<!-- Build dependencies -->
<dependency org="org.codehaus.sonar-plugins" name="sonar-ant-task" rev="2.1" conf="build->default"/>
<dependency org="org.jacoco" name="org.jacoco.ant" rev="0.6.3.201306030806" conf="build->default"/>
</dependencies>
</ivy-module>
所希望的配置在顶部声明。请注意如何设置一些操作。例如,“编译”依赖关系自动成为“运行时”和“测试”的一部分。
其次配置映射是关键:
- myconf->默认:包括传递依赖
- myconf->主:只要不依赖
Upvoted。但是,我意识到采用不同配置的可能性。我特别要求提供单独的IVY文件,因为我喜欢在多个项目中具有相同的“ANT任务依赖项”,并且具有单独的IVY文件可以很容易地检查(使用差异甚至符号链接),而使用解决方案时,您必须直观地检查文件来确保“ANT任务依赖性”确实是相同的(当然,这对你来说很重要)。我相信我已经实现了,但直到我发布自己的答案,我很高兴接受你的答案,因为这是一个伟大的写作。 –
顺便提一句,我不喜欢使用'ivy:cachepath',因为它对于实际包含的罐子有点不透明。即使对于“ANT任务依赖”,我也使用“ivy:retrieve”,因为我喜欢能够检查文件系统上的目录并查看所有带入的jar。“ivy:cachepath”没有提供这样的可见性我知道。 –
@MarcusJuniusBrutus请注意,我的“解决方案”目标是如何使用常青藤“报告”任务来生成每个配置上罐子的详细报告。 –