18

如何获取当前目标蚂蚁的值?

它是否存在一个名为 TARGET 的特殊变量?

4

5 回答 5

14

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>
于 2009-09-16T10:58:27.230 回答
11

在 ant 1.8.2 中,您可以使用 ${ant.project.invoked-targets}

但是,查看提交日志 http://svn.apache.org/viewvc?view=revision&revision=663061 我猜它从 1.7.1 开始可用

于 2011-03-01T15:43:24.963 回答
2

我的回答,使用 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"/>
于 2015-10-13T12:28:11.747 回答
1

我认为你不能,除非你花一些时间编写自己的自定义任务(http://ant.apache.org/manual/tutorial-writing-tasks.html

可以显示的内置属性有:basedir、ant.file、ant.version、ant.project.name、ant.java.version

于 2009-09-15T15:20:12.097 回答
1

如果您使用-projecthelparg 运行 ant:

ant -projecthelp

您将获得 build.xml(或命令行上声明的其他构建文件)中指定的主要目标的列表。

于 2009-09-15T15:23:35.163 回答