I'd like to suggest an enhancement. Take default values for the "source" and "target" arguments to the "javac" core task from properties, e.g. "build.source" and "build.target". This would allow creators of packages for distributions (e.g. Gentoo in my case) to specify or change those properties according to system configuration without modifying the build.xml file.
Please see <presetdef> documentation at http://ant.apache.org/manual/CoreTasks/presetdef.html.
I was thinking about a project with a build.xml that was written by someone else, doesn't provide any version information at all, and I don't want to modify the build file itself and still be able to compile the project with reasonable defaults for my system. In this case you'd either have to rewrite the build.xml to introduce those attrributes or to introduce using the presetdef defined task instead of the plain javac. I don't see much difference between those two approaches. Or is there a way to override core tasks by modified versions in an antlib by just using command line arguments?
You can create a separate build file with <presetdef> and <import> of the old build file.
... or write a build files that copies the original build file, inserts <presetdef/> just after <project.*?>, and executes <ant/> with new file.
IMHO people using <javac> should always specify source (which implies a reasonable target as well). If you wrote the sources, you know what source level they use, so you should declare it. There is no reason I can see to make this variable dependent on system config. (Obviously if some project is using a source level higher than that supported by the compiler Ant is running, you are in trouble, but using a magic value for the source level would just give you compiler errors anyway.) BTW the <javac> doc page already recommends that source always be explicit.