Cannot overwrite compileJava task in 1.7 nightly


I have a build that overwrites the compileJava task so that it can use the ant javac task.

task compileJava(type:CustomAntCompile, overwrite: true)

With the Gradle 1.7 nightly builds, I find that the overwrite has no effect and it invokes the Gradle compile java task. Is this by design? Will this not work with Gradle 1.7 onwards?

I’m not aware of any (intentional) changes. Note that ‘overwrite’ is (and has always been) half-broken in that it’s not defined if tasks originally depending on the old task will, after overwriting the task, depend on the new task. Therefore it’s best avoided. If absolutely necessary, you can instead overwrite a task’s actions, which usually works better.

Why do you want to use the Ant javac task, and why don’t you do it with ‘javaCompile.useAnt = true’?

Thanks, we are making use of the ‘sourcepath’ argument to break up the compile into smaller file sets (so that the memory required is manageable). The compileJava task will be preceded by other tasks that have already compiled the java files and hence compileJava is overwritten.

I found this other post that is related -

Overwriting the task actions should work and gives me other options to organize the build. Thanks, will try it out.

You can use the ‘sourcepath’ option with the original ‘compileJava’ task as well (both with ‘useAnt = true’ and ‘useAnt = false’).

That’s great! Was the sourcepath always supported or is it a recent change (> gradle 1.2) ?

It was always supported, as you could always (and still can) pass arbitrary compiler arguments to a ‘JavaCompile’ task.

Hey kiran, just noticed this thread. I think the main reason for the specific Compile task in your codebase was the specific definition of your in and outputs ( just Parts of your sources)