tags:

views:

601

answers:

3

I'm more accustomed to make, so I'm confused why ant recompiles classes when the source hasn't been changed. I've read that there is a requirement to recompile in some cases where generics are used, but I'm not sure that this will be necessary for my project.

Also, in the javac task, I've set includeDestClasses="true"

Here's some of the targets I'm using

<target name="init">
     <mkdir dir="${build}"/>
     <mkdir dir="${dist}"/>
    </target>
    <target name="compile" depends="init,util,semantics" description=""/>
    <target name="util" depends="" description="">
     <javac destdir="${build}" classpath="project.class.path" debug="on" srcdir="${src}/util" includeDestClasses="true" source="1.5">
      <classpath refid="project.class.path"/>
     </javac>
    </target>
+1  A: 

In my experience the javac target will not compile all the classes, only the ones in need of it, even without the includeDestClasses attribute. In fact I usually set up two (or more) compile targets, one that does a complete compile (forced by deleting the output directory) and one that does a quick updating compile, much like your javac line. Are you sure that one of your dependencies isn't deleting the output directory?

Glenn
I'm pretty sure, I just ran one of the sub targets and the timestamps were all updated in my dest dir.
Dana the Sane
I'm using 1.7.0, not 1.7.1. I just tried it after editing one file, and got a "[javac] Compiling 1 source file to ..." What happens without the includeDestClasses attribute? Your ant output should say how many files are being compiled.
Glenn
+4  A: 

Your src & dest directories are not equivalent, so ant is not able to effectively stat the output files to compare them.

This is an FAQ: http://ant.apache.org/faq.html#always-recompiles

eqbridges
THe src and dest attributes are specifically different to maintain the package hierarchy.
Dana the Sane
+5  A: 

Try modifying the opening tag of the javac task to include both a srcdir attribute and an includes attribute:

<javac destdir="${build}" classpath="project.class.path" debug="on" srcdir="${src}" includes="util/**" includeDestClasses="true" source="1.5">

Bobby Eickhoff
This seems to work, any idea why?
Dana the Sane
Yes, when ant looks for source files that have changed, it does not read the contents of any files -- in particular, it does not read any class's package declaration. Instead, it infers the fully-qualified name of a class from its filename and its placement in the source directory hierarchy. So, for example, you may have had a class util.codec.Base64 whose source code was at ${src}/util/codec/Base64.java, but your javac task was inferring its fully-qualified name as codec.Base64 because you told it that the root of the source code hierarchy was at ${src}/util instead of ${src}.
Bobby Eickhoff