2011-07-20 33 views
1

簡要解釋一下,下面是一個示例:[ANT] Property and Classpathref inherit broken in「foreach」

在build.xml中,導入了local-db.xml。在local-db.xml中,有一個名爲「warmup」的目標,它使用任務調用第三個文件的一個目標 - local-gr.xml。

所有常用屬性和類路徑defs都是在build.xml中導入和設置的。

在project.properties

<path id="gr-classpath"> ... </path> 
<import file="local-db.xml" /> 
在本地db.xml

dest-dir=./destination 
build.xml中

<ant antfile="local-gr.xml" target="deploy" inheritAll="true" inheritRefs="true" /> 

在本地gr.xml,有是這樣的兩個目標:

<target name="deploy"> 
    <tar ....../> 
    <foreach list="${list1}" delimiter="," parallel="true" trim="true" param="item" target="deploy-single" /> 
</target> 

<target name="deploy-single"> 
    something using property ${dest-dir} and path "gr-classpath" 
</target> 

現在,這裏的問題是:

屬性$「GR-類路徑」可在「部署」,因爲我設置inheritAll和inheritRefs使用{目的地-DIR}和路徑,但它不能直接使用在「部署單一」。當foreach調用目標時,「inherit」不會執行嗎?

我設法將$ {dest-dir}傳遞給「deploy-single」,但我沒有找到任何方法將classpathref「gr-classpath」傳遞給「deploy-single」。

我爲解決這個問題所做的一切就是在「deploy-single」中再次聲明,但我完全不喜歡它。

爲什麼會發生這種情況?我能做些什麼來使它更優雅?

回答

4

ant-contrib foreach task默認情況下不傳播所有屬性和對其目標的引用。但它具有inheritallinheritrefs屬性,您可以使用這些屬性來實現此目的。

<foreach list="${list1}" delimiter="," parallel="true" trim="true" 
     param="item" target="deploy-single" 
     inheritall="true" inheritrefs="true" 
/> 
+0

謝謝Martin!在我問這裏之前,我已經檢查過這個foreach文檔,並且學會編寫,但是我忽略了屬性列表! – coolcfan