Cannot overwrite compileJava task in 1.7 nightly


(kiran_anantha) #1

Hello,

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?


(Peter Niederwieser) #2

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’?


(kiran_anantha) #3

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 - http://forums.gradle.org/gradle/topics/replacing_tasks_overwrite_true_does_not_work_in_1_5

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


(Peter Niederwieser) #4

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


(kiran_anantha) #5

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


(Peter Niederwieser) #6

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


(René Groeschke) #7

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)