ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <>
Subject [Ant Wiki] Update of "AntOddities" by SteveLoughran
Date Wed, 07 Sep 2005 10:46:12 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Ant Wiki" for change notification.

The following page has been changed by SteveLoughran:

The comment on the change is:
why source=1.4, 1.5 required.

+ == Why does <javac> require you to set source="1.4" for Java1.4 features, "1.5" for
Java1.5? ==
+ The command line javac tool automatically selects the latest version of Java for the platform
you build on. So when you build on Java1.4, it is as if -source 1.4 was passed in, while on
Java1.5, you get the effect of -source 1.5
+ Yet on Ant, you have to explicitly say what version of the Java language you want to build
against. If you have the assert keyword in source and omit the source="1.4" attribute, the
compile will break. If you use fancy Java1.5 stuff and forget source="1.5", you get errors
when you hit enums, attributes, generics or the new for stuff.
+ Q. Why is this the case? Why doesnt Ant "do the right thing?"
+ A. Because of a deliberate policy decision by the project. 
+ Ant was written, first and foremost, to build open source projects. In such a project, you
don't know who builds your project; you just give out your source and rely on it compiling
everywhere, regardless of which platform or JVM the person at the far end used. We also assume
that a source tarball will still compile, years into the future.
+ If <javac> automatically selected the latest version of Java, then any Java1.2 code
that used "enum" as a variable name, or "assert". To build the old projects, you would have
to edit every build file that didnt want to use the latest Java version and force in a source="1.3"
attribute. Except if they were other people's projects, you would have to struggle to get
that change committed, and things like ApacheGump would never work, because all old-JVM projects
would never compile straight from the SCM repository. 
+ That is why, in Ant, if you want the latest and greatest features of the Java language,
you have to ask for them. By doing so you are placing a declaration in your build file what
language version you want to use, both now and into the future.
+ An interesting follow-on question is then "why does javac on the command line risk breaking
every makefile-driven Java project by automatically updating Java language versions unless
told not to?" That is for Sun to answer, not the Ant team.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message