Bug 35325 - javac: properties for default source and target version
Summary: javac: properties for default source and target version
Status: RESOLVED WORKSFORME
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.6.2
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL: https://bugs.gentoo.org/show_bug.cgi?...
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-11 00:52 UTC by Martin von Gagern
Modified: 2008-02-22 12:18 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin von Gagern 2005-06-11 00:52:59 UTC
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.
Comment 1 Alexey Solofnenko 2005-06-11 01:40:30 UTC
Please see <presetdef> documentation at 
  http://ant.apache.org/manual/CoreTasks/presetdef.html.
Comment 2 Martin von Gagern 2005-06-11 02:06:23 UTC
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?
Comment 3 Alexey Solofnenko 2005-06-11 02:15:14 UTC
You can create a separate build file with <presetdef> and <import> of the old build file.
Comment 4 Alexey Solofnenko 2005-06-11 02:17:54 UTC
... or write a build files that copies the original build file, 
inserts <presetdef/> just after <project.*?>, and executes <ant/> with new file.
Comment 5 Jesse Glick 2005-06-11 08:46:03 UTC
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.