【问题标题】:Ant build - javac task - exclude a dir then include a subdirAnt 构建 - javac 任务 - 排除一个目录,然后包含一个子目录
【发布时间】:2015-08-27 09:02:21
【问题描述】:
我有一棵这样的树
path/a
path/b
path/c
path/d/da
path/d/db
path/d/dc
现在在我的 javac 任务中我想要
- 编译
path/中的所有内容
- 排除
path/d/中的所有内容
- 编译
path/d/db/中的所有内容
像这样:
path/a
path/b
path/c
path/d/db
我玩过包含/排除和模式集,但我无法实现我需要的。
有没有办法做到这一点?
【问题讨论】:
标签:
java
ant
javac
build.xml
【解决方案1】:
<difference> and <union> set operations 可以满足您的需要。
以下 Ant 脚本展示了如何将多个 <fileset> 元素组合为一个:
<project name="ant-javac-include-and-exclude" default="run" basedir=".">
<target name="run">
<fileset id="all-files" dir="path">
<include name="**"/>
</fileset>
<fileset id="files-under-d" dir="path">
<include name="d/**"/>
</fileset>
<fileset id="files-under-d-db" dir="path">
<include name="d/db/**"/>
</fileset>
<!-- Matches all files under a, b, c -->
<difference id="all-files-NOT-under-d">
<fileset refid="all-files"/>
<fileset refid="files-under-d"/>
</difference>
<!-- Combine all files under a, b, c and under d/db -->
<union id="files-to-compile">
<difference refid="all-files-NOT-under-d"/>
<fileset refid="files-under-d-db"/>
</union>
<!-- Convert the absolute paths in "files-to-compile" to relative-->
<!-- paths. Also, "includes" of <javac> requires a comma-separated -->
<!-- list of files. -->
<pathconvert property="union-path" pathsep=",">
<union refid="files-to-compile"/>
<map from="${basedir}/" to=""/>
</pathconvert>
<javac
srcdir="."
includes="${union-path}"
includeantruntime="false"
/>
</target>
</project>
以上步骤可以组合成以下:
<pathconvert property="union-path" pathsep=",">
<union>
<difference>
<fileset dir="path">
<include name="**"/>
</fileset>
<fileset dir="path">
<include name="d/**"/>
</fileset>
</difference>
<fileset dir="path">
<include name="d/db/**"/>
</fileset>
</union>
<map from="${basedir}/" to=""/>
</pathconvert>
<javac
srcdir="."
includes="${union-path}"
includeantruntime="false"
/>