Differences in ant java compile vs gradle java compile


(rajesh.eq) #1

I am compiling few Java files using gradle and I noticed the size of the output .class files are not same when compiled using ant javac target (for the same source files). I checked the sourceCompatibility, targetCompatibility, options.forkOptions.executable, options.fork properties and they remain the same in both ant and gradle. Any reason why gradle JavaCompiled class files size differs with ant Javac class files?


(Peter Niederwieser) #2

Most likely your Ant build doesn’t include debug information in the class files (see ‘options.debugOptions’).


(rajesh.eq) #3

Thats right. In ant javac debug information is by default turned off but in gradle JavaCompile debug is by default set to true. options.debug is mentioned as deprecated in documentation. So how should I turn off the debug information without using options.debug?


(Peter Niederwieser) #4

‘CompileOptions#getDebug’ has been deprecated in favor of ‘CompileOptions#isDebug’. ‘options.debug = false’ (which is shorthand for ‘options.setDebug(false)’) should be fine.


(Kevin Maskell-Moody) #5

Just a quick question…how in the world did you find the defaults for JavaCompile, which are set by the JavaPlugin. I looked all over JavaCompile, JavaPluginConvention, etc. API docs and don’t see where ‘-g’ is specified as the default. I didn’t check the JavaPlugin source, yet…


(Peter Niederwieser) #6

The defaults for ‘CompileOptions#debug’ and ‘DebugOptions#debugLevel’ are documented in the Javadoc, which the Gradle Build Language Reference for ‘JavaCompile’ links to.


(Kevin Maskell-Moody) #7

Wow. I’m blind. I must’ve been distracted by the ‘deprecated’ in ‘CompileOptions#debug’ and looked right past the default value. Sorry about that.