2011-04-15 60 views
1

我想我不能「得到」Ant。我很難搞清楚如何實現重用和控制一系列目標的執行。請幫忙。Ant中的重用和執行控制

我需要我的構建腳本來創建兩個構建:調試構建和生產構建。目前我使用antcall來破解我對Ant的誤解。

讓我用僞勢在必行代碼來描述我多麼希望我的建立去:

//this is my entry point 
function build-production-and-debug() = 
    prepare() 
    build-production() 
    build-debug() 
    cleanup() 

function build-production() = 
    pre-process() 
    compile() 
    post-process() 
    package("production") 

function build-debug() = 
    compile() 
    package("debug") 

我怎麼想用螞蟻接近這個?

回答

1

下面是我想出的概要,我仍然使用antcall s,但只是作爲參考我的構建的入口點。對我來說,關鍵的發現是在目標上使用if條件來控制目標是否被執行,並指出其依賴鏈中的目標仍然執行。 conditionisset任務在某些地方也有幫助。

<project> 
    <target name="-init"> 
    </target> 

    <target name="-prod-preprocess" depends="-init" if="production"> 
    </target> 

    <target name="-compile" depends="-prod-preprocess"> 
    </target> 

    <target name="-package" depends="-compile"> 
    </target> 

    <target name="build-prod"> 
     <property name="production" value="true" /> 
     <property name="package.dir" location="${production.package.location}"/> 
     <antcall target="-package" /> 
    </target> 

    <target name="build-debug"> 
     <property name="package.dir" location="${debug.package.location}"/> 
     <antcall target="-package" /> 
    </target> 

    <target name="build-both"> 
     <antcall target="build-debug" /> 
     <antcall target="build-prod" /> 
    </target> 
</project> 
2

也許你可以把你的螞蟻代碼給出一個更好的答案。 但要做到這一點的方法之一是使用依賴屬性

<target name="prepare"> 
    //do something to prepare 
</target> 
<target name="cleanup"> 
    //do something to cleanup 
</target> 

<target name="build-production"> 
    //build production 
</target> 

<target name="build-debug"> 
    //build debug 
</target> 

<target name="build-production-debug" depends="prepare,build-production, build-debug, cleanup"> 
     //do something or nothing 
</target> 

這樣,你就告訴螞蟻之前執行「建設生產調試」的目標,你想先運行「中列出的所有目標取決於「屬性是按照該順序執行的。

+0

嗨@Dave,謝謝你的回答,抱歉,我沒有提供足夠的信息來幫助你。取決於這裏是不夠的,因爲我需要更像「準備 - >構建 - 生產 - >清理」*然後*「準備 - >構建 - 調試 - >清理」。 – 2011-04-20 15:31:42