How to enable asserts when building with Ant


Can anyone explain how to setup IDEA to allow asserts when building via Ant.

I have an assert statement in a java source file. Using Ant's javac task to compile gives the following errors: (1064:9)not a statement not a statement (1064:16)';' expected ';' expected

The line in question is:

assert !objects.isEmpty() : "no object defined";

In my IDEA settings JDKs I have JDK1.4.2_02 set.
Further in my Ant build.xml file I have the following property set:


My understanding is that Ant uses the default JDK or a sdpecific JDK version if the global "build.compiler" property is set. Both of these are true in my case yet the build errors are those that I would expect to see if a
pre 1.4 javac was used for the compilation.


Tim Mowlem

Comment actions Permalink

With respect to my question I forgot to mention that I have also checked the "Enable asserts keyword" checkbox in the Project Paths settings and restarted IDEA.

Comment actions Permalink

You need to add a "source" attribute to your javac tasks, with argument "1.4". Here's an example.


--Dave Griffith


Please sign in to leave a comment.