I am trying to write ant build for compiling source folder here is my script target for compiling.
As I understand, compiling only the modified java files is the default behavior of ant javac task. Ant uses the timestamp of a .java file and its corresponding .class file to determine if the a Java file needs to be recompiled. I have used it in many projects and never have issues.
Here are a few things you can check
Is your source tree directory structure matching your Java package structure? Please see Why does ant always recompile all my Java files?. This is probably the number 1 reason since it is in the FAQ.
I see your compile
target depends on init
target? What does the init
target do? Does it depends on any clean
target or does it cleanup the .class files?
What is your ant version? Can you try a different ant version to see if you still have the same problem?
If none of the above fixes your issue, after the compilation, can you manually check the .class file timestamp and compare it with the timestamp of the corresponding .java file?