Why does javac not check timestamps?

Dependency-checking works fine with javac (e.g. you only need to specify x.java as the argument and y.java, if referenced by x.java, is automatically compiled).

However, when y.java is updated and there is already a file called y.class, y.java is not recompiled.

Why is that? Wouldn't it be trivial to add that feature to javac and make advanced build tools unneccessary?

Message was edited by:

byte008

[435 byte] By [byte008a] at [2007-11-26 23:37:59]
# 1
It does, and it's documented to do so ( http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javac.html), and it's been doing so for at least eleven years to my knowledge. Are you sure about the timestamps on the files? maybe some server time-sync or DST problem?
ejpa at 2007-7-11 15:02:00 > top of Java-index,Developer Tools,Java Compiler...
# 2

From Sun:

"If A uses B and B is changed, A.java would not be recompiled unless explicitly specified. On the other hand, each explicitly passed source is always recompiled, whether this is really required or not."

(URL: http://www.experimentalstuff.com/Technologies/JavaMake/index.html)

byte008a at 2007-7-11 15:02:00 > top of Java-index,Developer Tools,Java Compiler...
# 3

That's not inconsistent with what I said.

Also from Sun:

'javac determines whether the class file is out of date. If the class file is out of date, javac recompiles the source file and uses the updated class file. Otherwise, javac just uses the class file.'

That specifically counters your statement 'y.java, if referenced by x.java, is automatically compiled). However, when y.java is updated and there is already a file called y.class, y.java is not recompiled.'

The difference might appear subtle but it is there. What javac doesn't do is chase other classes which are dependent on B (or Y) if B/Y is recompiled by the rule above. It only explores the dependencies of the class trees starting at the classes passed in the command line.

Given that it's a compiler which is specified to compile what you specify on the command line and its dependencies,I think that that's reasonable. Compiling things out of that tree is more in the province of a build tool to me. Or jikes.

ejpa at 2007-7-11 15:02:00 > top of Java-index,Developer Tools,Java Compiler...