如何获取当前目标蚂蚁的值?
它是否存在一个名为 TARGET 的特殊变量?
Based on the issue you have to patch ant or used javascript:
<target name="test">
<script language="javascript">
project.setNewProperty("current_target", self.getOwningTarget());
</script>
<echo>${current_target}</echo>
</target>
在 ant 1.8.2 中,您可以使用 ${ant.project.invoked-targets}
但是,查看提交日志 http://svn.apache.org/viewvc?view=revision&revision=663061 我猜它从 1.7.1 开始可用
我的回答,使用 antcontrib
<macrodef name="showtargetname">
<attribute name="property"/>
<sequential>
<!-- make temporary variable -->
<propertycopy name="__tempvar__" from="@{property}"/>
<!-- Using Javascript functions to convert the string -->
<script language="javascript"> <![CDATA[
currValue = [project-name].getThreadTask(java.lang.Thread.currentThread()).getTask().getOwningTarget().getName();
[project-name].setProperty("__tempvar__", currValue);
]]>
</script>
<!-- copy result -->
<var name="@{property}" value="${__tempvar__}"/>
<!-- remove temp var -->
<var name="__tempvar__" unset="true"/>
</sequential>
</macrodef>
用法:
<showtargetname property="mycurrenttarget"/>
我认为你不能,除非你花一些时间编写自己的自定义任务(http://ant.apache.org/manual/tutorial-writing-tasks.html)
可以显示的内置属性有:basedir、ant.file、ant.version、ant.project.name、ant.java.version
如果您使用-projecthelp
arg 运行 ant:
ant -projecthelp
您将获得 build.xml(或命令行上声明的其他构建文件)中指定的主要目标的列表。