Bug 30716

Summary: javac task fails to recompile java files that have external dependencies
Product: Ant Reporter: Alon Albert <aalbert>
Component: Core tasksAssignee: Ant Notifications List <notifications>
Status: NEW ---    
Severity: major    
Priority: P2    
Version: 1.7.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Simple test suite for testing javac ant task.

Description Alon Albert 2004-08-17 22:00:38 UTC
The javac task has an annoying limitation that causes many users to have to run 
clean before building a slightly updated project.

This is because javac task only compiles out dated files but it isn't very 
clever about dependancies. It simply maps a *.java file against a *.class file. 
There exists an optional ant task called depend that is smarter about this. It 
detects real dependancies by digging into the class file themselves.

Running the depend task before the javac task will resolve the issue but most 
people arn't aware of this. Also, having to specify the srcdir & destdir twice 
can be a source for errors.

Rather, javac task should utilize the existing code found in depend task to 
build a proper outdated list.
Comment 1 Jacob Abrams 2010-04-15 17:14:29 UTC
Created attachment 25305 [details]
Simple test suite for testing javac ant task.
Comment 2 Jacob Abrams 2010-04-15 17:20:37 UTC
I believe this is more than just an enhancement request, it is actually a bug. I don't think these two situations should ever produce different results:

1. calling javac with a destination directory that contains some previously compiled .class files
2. calling java with an empty destination directory

If these produce different results then no programmer will ever trust existing .class files and will want to clean them every time.

Please see the attached test suite that demonstrates the issue, just change the int value in R.java to something else and run:

1. ant compile
2. ant run

Notice that the change never takes effect, but if you do the following it does:

1. ant clean
2. ant compile
3. ant run

This is because static final integers are copied into the class files using them, even if those class files don't change they need to be recompiled if the int does. The simple algorithm used by ant to determine dependency is causing this problem and should be eliminated.