Ant: How to know if at least one copy task from te

2019-08-31 03:10发布


I have a target which has several copy tasks; It basically copies the common jars to our set of applications from a centralized location to the lib folder of the application.
Seeing as this is a regular copy task a jar will be copied only if it is newer than the one currently in the lib folder.
This is the relevant part in the build.xml:

<target name="libs"/>  
  <copy file=... />  
  <copy file=... />  
  <copy file=... />  
  <antcall target="clean_compiled_classes"/>  
</target>  
<target name="clean_compiled_classes" if="anyOfTheLibsWereCopied">  
  <delete .../>  
</target>

I'm looking for a way to set the anyOfTheLibsWereCopied property before the ant call in the libs target based on whether or not any of the files has been actually changed.

Thanks,
Ittai

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-31 03:37

I would advise having a look at the Uptodate task. I have never used it before but I guess what you are trying to do will be implemented along the following lines:

<target name="libs"/>
  <uptodate property="isUpToDate">
    <srcfiles dir="${source.dir}" includes="**/*.jar"/>
    <globmapper from="${source.dir}/*.jar" to="${destination.dir}/*.jar"/>
  </uptodate>
  <!-- tasks below will only be executed if
       there were libs that needed an update -->
  <antcall target="copy_libs"/>  
  <antcall target="clean_compiled_classes"/>  
</target>

<target name="copy_libs" unless="isUpToDate">  
  <copy file=... />  
  <copy file=... />  
  <copy file=... />
</target>

<target name="clean_compiled_classes" unless="isUpToDate">  
  <delete .../>
</target>

Your other option would be to implement your own ant task that does what you want. This would require a bit more work though.

查看更多
登录 后发表回答