Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ant compile all classes each run?

Tags:

java

ant

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>
like image 307
Dana the Sane Avatar asked May 06 '09 01:05

Dana the Sane


People also ask

Which Ant task does the Java compiling?

Ant Javac task is used to compile Java source file. It scans source and destination directory to compile the source file. It only compiles if either . class is not present or .

What is PathElement in Ant?

Path: This object represents a path as used by CLASSPATH or PATH environment variable. A path might also be described as a collection of unique filesystem resources. and PathElement: Helper class, holds the nested <pathelement> values.

What is includeAntRuntime in Ant?

includeAntRuntime. Whether to include the Ant run-time libraries in the classpath. It is usually best to set this to false so the script's behavior is not sensitive to the environment in which it is run. No; defaults to yes , unless build.sysclasspath property is set. includeJavaRuntime.


3 Answers

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">

like image 90
Bobby Eickhoff Avatar answered Sep 18 '22 19:09

Bobby Eickhoff


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

like image 29
Edward Q. Bridges Avatar answered Sep 18 '22 19:09

Edward Q. Bridges


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?

like image 41
Glenn Avatar answered Sep 19 '22 19:09

Glenn