> But the 'lost-update' issue is a much more serious one. Dead serious, I > might say, the problem is that the way the javac task is designed > (again, it could well be my fault since I enhanced that task a lot in > the past) is that is path based.
The problem is not with the <javac> task, it is with JavaTM itself. I've said it on this list before, I know, but I just can't stop myself... <soapbox> JavaTM <em>needs</em> an integrated preprocessor. Without anyway to instruct IDEs (such as with a #line directive), IDEs simply cannot distinguish between the preprocessed and source files, leaving developers to figure it out themselves. </soapbox> Short of modifying javac, there is no real solution to this. My projects that require preprocessing use one of two strategies: 1. Use preprocessing on all files in the project. 2. Separate, by extension, those java source files in the project that require preprocessing and handle them separately before compiling everything else. I use 1 when virtually every file in a project requires preprocessing (think jdbc) and 2 when only a few files do, such as a Constants.java file. To handle the first strategy, I just replace <javac> with <vppjavac> (see vpp.sourceforge.net) which nicely handles my preprocessing needs. For the second strategy: 1. Any file that needs preprocessing gets a .java.vpp extension. 2. Preprocess all files with the .java.vpp extension sending output to an gen directory _not_ in your regular source directory. 3. Compile everything normally, including the gen directory as an additional src path. Using the extension both identifies the file as needing preprocessing and also prevents it from being compiled directly. Changes of course can still be made to the generated code, but at least they will have to be made to a file outside the normal source directory path, cluing you into the fact that the file was preprocessed. I also include a comment in the file that says something to the effect, "This file was preprocessed, changes made to it will be lost, the source for this file is located at ...". Here's essentially the kind of target I use for building: <target name="build" > <vpp todir="gen" overwrite="true"> <fileset dir="src" includes="**/*.java.vpp"/> <mapper type="glob" from="*.java.vpp" to="*.java"/> </vpp> <javac destdir="build/classes"> <src path="src"/> <src path="gen"/> </javac> </target> I used <vpp>, but I'm sure this example could be easily changed to use a <copy> with filtering, as well. didge