【问题标题】:How to execute an Ant task only when source files have been modified?只有在源文件被修改的情况下,如何执行 Ant 任务?
【发布时间】:2009-02-02 16:46:17
【问题描述】:

必须有一个简单的方法来做到这一点。我使用依赖于 SWC 库的 ant 构建了一个 Flex 应用程序,除了它是否需要重建库之外,它工作正常。如果库的任何源文件(*.as、*.mxml)比 SWC 更新,我如何告诉 ant 只运行任务?

我看过 但它似乎只是删除文件,而不是确定是否应该运行任务。 似乎期望源文件和目标文件之间存在一对一的关系,而不是一对多的关系——我有许多输入文件和一个输出文件,但没有中间目标文件。

非常感谢, 亚历克斯

【问题讨论】:

    标签: apache-flex ant dependencies


    【解决方案1】:

    您可以使用 Ant uptodate task 创建一个属性,并仅在设置该属性时执行您的其他目标。

    我对 flex 了解不多,但您可能想要这样的东西:

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="test" default="compile">
    
       <target name="checkforchanges">
          <uptodate property="nochanges">
             <srcfiles dir="." includes="**/*.as"/>
             <srcfiles dir="." includes="**/*.mxml"/>
             <mapper to="applicaton.flex"/>
          </uptodate>
       </target>
    
       <target name="compile" depends="checkforchanges" unless="nochanges">
          ...
       </target>
    
    </project>
    

    【讨论】:

    • 谢谢!这是我现在使用的: <uptodate property="playerlib.notRequired" targetfile="${playerlib.swc}"><srcfiles dir="${src.dir}" includes="&lt;i&gt;* /&lt;/i&gt;.as"></srcfiles><srcfiles dir="${src.dir}">*/.mxml"/&gt; <srcfiles dir="${basedir}">*/.xml"/&gt; </srcfiles></srcfiles></uptodate>
    • 我相信“编译”目标,你应该使用“除非”而不是“如果”。我可能是错的......
    • 你是对的。我在这里得到了错误的想法(并且需要一些时间来实现它)。谢谢。我也以错误的方式命名了该属性。我会改变我的答案。
    【解决方案2】:

    ant contrib 库中的 OutOfDate 任务在 IMO 中比 Ant uptodate 选项更简洁。原因是您必须定义其他目标才能设置属性。

    Ant contrib 的解决方案(来自他们的示例页面):

    <outofdate>
        <sourcefiles>
            <pathelement path="build.xml"/>
            <fileset dir="${lib.dir}"/>
        </sourcefiles>
        <targetfiles path="${jrun.file}"/>
        <sequential>
            <mkdir dir="${build.bin.dir}"/>
            <echo file="${jrun.file}" message="java -cp ${jrun.path} $*"/>
            <chmod file="${jrun.file}" perm="ugo+rx"/>
        </sequential>
    </outofdate> 
    

    一切都很好地保存在一个目标中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-02
      • 1970-01-01
      • 2020-11-21
      • 2023-04-02
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 2023-04-01
      相关资源
      最近更新 更多