W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
你可以在你的gradle項(xiàng)目中通過ant.importBuild()來導(dǎo)入一個(gè)ant構(gòu)建,當(dāng)你導(dǎo)入了一個(gè)ant構(gòu)建,每一個(gè)ant target都會(huì)被視為一個(gè)Gradle任務(wù).這意味著你可以像操作,執(zhí)行g(shù)radle任務(wù)一樣操作,執(zhí)行ant target
例 16.8.導(dǎo)入ant構(gòu)建
build.gradle
ant.importBuild 'build.xml'
build.xml
<project>
<target name="hello">
<echo>Hello, from Ant</echo>
</target>
</project>
gradle hello的輸出
>\> gradle hello
>:hello
>[ant:echo] Hello, from Ant
>
>BUILD SUCCESSFUL
>
>Total time: 1 secs
你可以添加一個(gè)依賴于ant target的任務(wù): 例 16.9.依賴于ant target的任務(wù)
build.gradle
ant.importBuild 'build.xml'
task intro(dependsOn: hello) << {
println 'Hello, from Gradle'
}
gradle intro的輸出 > gradle intro :hello [ant:echo] Hello, from Ant :intro Hello, from GradleBUILD SUCCESSFULTotal time: 1 secs
或者,你可以為ant target添加動(dòng)作
例 16.10.為Ant target添加動(dòng)作
build.gradle
ant.importBuild 'build.xml'
hello << {
println 'Hello, from Gradle'
}
gradle hello的輸出
> gradle hello :hello [ant:echo] Hello, from Ant Hello, from GradleBUILD SUCCESSFULTotal time: 1 secs
當(dāng)然,一個(gè)ant target也可以依賴于gradle的任務(wù)
例 16.11.為Ant target添加動(dòng)作
build.gradle
ant.importBuild 'build.xml'
task intro << {
println 'Hello, from Gradle'
}
build.xml
<project>
<target name="hello" depends="intro">
<echo>Hello, from Ant</echo>
</target>
</project>
gradle hello的輸出
> gradle hello :intro Hello, from Gradle :hello [ant:echo] Hello, from AntBUILD SUCCESSFULTotal time: 1 secs
有時(shí)候可能需要'重命名'ant target以避免與現(xiàn)有的gradle任務(wù)沖突.需要使用AntBuilder.importBuilder())方法.
例 16.12.重命名導(dǎo)入的ant target
build.gradle
ant.importBuild('build.xml') { antTargetName ->
'a-' + antTargetName
}
build.xml
<project>
<target name="hello">
<echo>Hello, from Ant</echo>
</target>
</project>
gradle a-hello的輸出
> gradle a-hello :a-hello [ant:echo] Hello, from AntBUILD SUCCESSFULTotal time: 1 secs
注意,方法的二個(gè)參數(shù)應(yīng)該是一個(gè)TransFormer,在Groovy編程的時(shí)候,由于Groovy的支持自動(dòng)閉包單抽象方法的類型。我們可以簡(jiǎn)單地使用閉包取代匿名內(nèi)部類,
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: