1

我试图找出可能导致 Ant 无法重建具有更新源的依赖项的原因。

我有几个包,每个包在 Ant 中都有自己的构建目标。其中一个目标 mds 依赖于另一个目标 robotsim。如果我没有在依赖项列表中添加它,我会出现疯狂的行为,它只会在有时构建,我想了解何时以及为什么。

$ ant clean mds
...
BUILD SUCCESSFUL

此时我在robotsim包中打开一个java文件并删除一个分号。

$ ls -l src/com/robotsim/model/Robot.java 
-rw-rw-r-- 1 matt matt 6.3K 2012-05-15 14:28 src/com/robotsim/model/Robot.java
$ ls -l build/com/robotsim/model/Robot.class 
-rw-rw-r-- 1 matt matt 6.6K 2012-05-15 14:13 build/com/robotsim/model/Robot.class
$ ant mds
...
BUILD SUCCESSFUL
$ ant clean mds
...
[javac] Robot.java:110: ';' expected
...
BUILD FAILED

那么问题来了,为什么第二次构建成功了?

编辑以包含 build.xml 的相关部分:

<target name='init'>
    <mkdir dir='${build.dir}'/>
    <mkdir dir='${dist.dir}'/>
</target>
...
<target name='customTasks'>
    <javac srcdir='${customTasks.src.dir}' destdir='${ant.library.dir}' classpathref='customTasks.classpath' failonerror='false'/>
    <taskdef name='protoc' classname='com.hrilab.Protoc' classpath="${ant.library.dir}"/>
</target>
...
<target name='algorithms' depends='init' extensionOf='compile' description='Builds a few generic algorithms'>
    <build-java package.dir='com/algorithms'/>
</target>
...
<target name='engine3d' depends='init' extensionOf='compile' description='Builds the 3D engine'>
    <build-java package.dir='com/engine3D'/>
</target>
...
<target name='humanoid' depends='init,utilities' extensionOf='compile' description='Builds the humanoid servers.'>
    <build-java package.dir='com/humanoid'/>
</target>
...
<target name='mds' depends='init,algorithms,engine3d,humanoid' extensionOf='compile' description='Builds the servers for the Xitome MDS.'>
    <build-java package.dir='com/mds'/>
</target>
...
<target name='robotsim' depends='init,customTasks' extensionOf='compile' description='Builds the 3D robot simulator'>
    <protoc minversion='2.4.0' srcfile='com/robotsim/calibration/leng/calibration_server_config.proto' destdir='${src.dir}'/>
    <protoc minversion='2.4.0' srcfile='com/robotsim/calibration/leng/extrinsic_parameters_collection.proto' destdir='${src.dir}'/>
    <build-java package.dir='com/robotsim'/>
</target>
...
<target name='utilities' depends='init' extensionOf='compile' description='Builds some common utilities'>
    <build-java package.dir='utilities'/>
</target>
...
<macrodef name='build-java'>
    <attribute name='classpath' default='base.classpath'/>
    <attribute name='package.dir' default='NOT SET'/>
    <attribute name='package.mask' default='**'/> <!-- HACK: please do not use this attribute, it's only here to hack around the way we have our source laid out -->
    <sequential>
        <javac srcdir='${src.dir}' destdir='${build.dir}' includes='@{package.dir}/@{package.mask}' debug='${debug.enabled}' debuglevel='${debug.level}'>
            <classpath refid='@{classpath}'/>
        </javac>
    </sequential>
</macrodef>
4

0 回答 0