短前面回答是使用常春藤配置:
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請注意,我的「解決方案」目標是如何使用常青藤「報告」任務來生成每個配置上罐子的詳細報告。 –