2017-02-10 65 views
0

有沒有辦法選擇當我調用ivy:retrieve時使用哪個ivy.xml文件?常春藤:檢索選擇使用哪個ivy.xml文件

尋找at the documentation看來我可以使用settingsRef屬性來選擇其中IVY設置文件使用,但它不是ivysettings.xml文件我想修改,而它的ivy.xml。我的使用情況如下:

  • 我有一個主ivy.xml文件,我用它來取我的編譯時和運行時的依賴
  • 我也有一些構建工具鏈的依賴關係,即罐子由某些Ant任務自己使用(例如findbugs,cobertura,pmd,代碼樣式符合性檢查等)。這是既不是編譯時間也不是我的代碼的運行時依賴。此外,在我使用此工具鏈構建的所有項目中都是如此,因此我希望能夠在單個獨立的ivy.xml文件中識別這些依賴關係,我可以簡單地在我的項目中進行復制。

回答

0

所以模塊罐子這就是我最後的表現:

<target name="fetch-buildsystem-deps" depends="configure-ivy-settings"> 
    <ivy:resolve file="ivy-buildsystem.xml"/> 
    <ivy:retrieve conf="build-system" 
        pattern="${lib-ivy-buildsystem.dir}/[artifact]-[revision](-[classifier]).[ext]" 
        sync="true" 
        type="jar, bundle"/> 
</target> 

&hellip;文件ivy-buildsystem.xml只標識了我常春藤任務的依賴關係。例如。包含以下內容:

<configurations> 
    <conf name="build-system" description="artifacts needed by the build-system itself"/> 
</configurations> 
<dependencies> 
    <!--dependency org="ant-contrib" name="ant-contrib" rev="1.0b3" conf="build-system->master"/--> 
    <dependency org="com.puppycrawl.tools"  name="checkstyle" rev="5.9" conf="build-system->default"/> 
    <dependency org="com.google.code.findbugs" name="findbugs-ant" rev="3.0.0" conf="build-system->default"/> 
    <dependency org="net.sourceforge.pmd"  name="pmd-java"  rev="5.5.3" conf="build-system->default"/> 

</dependencies> 
2

短前面回答是使用常春藤配置:

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->主:只要不依賴
+0

Upvoted。但是,我意識到採用不同配置的可能性。我特別要求提供單獨的IVY文件,因爲我喜歡在多個項目中具有相同的「ANT任務依賴項」,並且具有單獨的IVY文件可以很容易地檢查(使用差異甚至符號鏈接),而使用解決方案時,您必須直觀地檢查文件來確保「ANT任務依賴性」確實是相同的(當然,這對你來說很重要)。我相信我已經實現了,但直到我發佈自己的答案,我很高興接受你的答案,因爲這是一個偉大的寫作。 –

+0

順便提一句,我不喜歡使用'ivy:cachepath',因爲它對於實際包含的罐子有點不透明。即使對於「ANT任務依賴」,我也使用「ivy:retrieve」,因爲我喜歡能夠檢查文件系統上的目錄並查看所有帶入的jar。「ivy:cachepath」沒有提供這樣的可見性我知道。 –

+0

@MarcusJuniusBrutus請注意,我的「解決方案」目標是如何使用常青藤「報告」任務來生成每個配置上罐子的詳細報告。 –