This can be simplified to:
compileJava {
options.encoding = 'utf-8'
options.fork = true
doFirst {
options.forkOptions.with {
executable = 'java'
jvmArgs = [ '-cp', configurations.ecj.asPath, 'org.eclipse.jdt.internal.compiler.batch.Main' ]
}
}
}
We could think about making it easier to execute Java compilers from a main method, or add special support for the Eclipse compiler. Ant’s ‘options.compiler’ is unlikely to come back because Gradle’s ‘Compile’ task is slowly but surely moving away from Ant. Of course, you’ll always be able to use an Ant task (like javac) directly.