[英]Conditional ivysettings file in Ant
我正在尝试调整Ant build.xml脚本,以便能够在我们的本地办公室网络和AWS中工作。 因此,我必须使用不同的ivysettings.xml文件,具体取决于构建的位置。 在这两种情况下,构建都在Jenkins开始。 我的想法是在从AWS开始时注入属性'aws = true',否则属性不存在。 我们在AWS中使用Ant 1.7.1本地版本和更新版本,但我现在无法看到哪一个版本,build.xml应该能够在两者上运行,因此1.7.1是限制。 如有必要,我可以升级。
有人可以帮助我使用为此目的调整build.xml文件所需的语法吗?
<!-- Resolve dependencies -->
<target name="resolve" description="retrieve dependencies with ivy">
<ivy:settings file="ivysettings.xml"/>
<ivy:retrieve sync="true"/>
</target>
如果aws = true我想使用名为ivysettings_aws.xml的文件,否则使用ivysettings.xml。
谢谢。
我用ant_contrib想出来了。
<!-- Resolve dependencies -->
<target name="resolve" description="retrieve dependencies with ivy">
<if>
<equals arg1="${aws}" arg2="true" />
<then>
<ivy:settings file="ivysettings_aws.xml"/>
</then>
<else>
<ivy:settings file="ivysettings.xml"/>
</else>
</if>
<ivy:retrieve sync="true"/>
</target>
作品。
以下会更简单吗?
<property name="ivy.settings" value="ivysettings.xml"/>
<target name="resolve" description="retrieve dependencies with ivy">
<ivy:settings file="${ivy.settings}"/>
..
</target>
然后指定备用设置文件,如下所示:
ant -Divy.settings=ivysettings_aws.xml ..
您应该使用Ant 1.9.1中引入的新的if / unless功能来消除对antcontrib的额外依赖,这是近10年前最新版本 1.0b3的服务。
就像是 :
<project
xmlns:if="ant:if"
xmlns:unless="ant:unless"
>
<!-- Resolve dependencies -->
<target name="resolve" description="retrieve dependencies with ivy">
<ivy:settings file="ivysettings_aws.xml" if:true="${aws}"/>
<ivy:settings file="ivysettings.xml" unless:true="${aws}"/>
<ivy:retrieve sync="true" />
</target>
</project>
或者使用Mark O'Connor提出的解决方案,但您需要记住更改-Divy.settings=...
参数以满足您的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.