# Cannot overwrite compileJava task in 1.7 nightly

**URL:** <https://discuss.gradle.org/t/cannot-overwrite-compilejava-task-in-1-7-nightly/2156>\
**Category:** Old Forum Archive\
**Created:** [May 31, 2013, 9:32pm UTC](https://discuss.gradle.org/t/cannot-overwrite-compilejava-task-in-1-7-nightly/2156 "2013-05-31T21:32:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kiran\_Anantha](https://avatars.discourse-cdn.com/v4/letter/k/eb8c5e/32.png) [@Kiran\_Anantha](https://discuss.gradle.org/u/Kiran_Anantha)\
**Post date:** [May 31, 2013, 9:32pm UTC](https://discuss.gradle.org/t/cannot-overwrite-compilejava-task-in-1-7-nightly/2156/1 "2013-05-31T21:32:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 31, 2013, 9:37pm UTC](https://discuss.gradle.org/t/cannot-overwrite-compilejava-task-in-1-7-nightly/2156/2 "2013-05-31T21:37:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kiran\_Anantha](https://avatars.discourse-cdn.com/v4/letter/k/eb8c5e/32.png) [@Kiran\_Anantha](https://discuss.gradle.org/u/Kiran_Anantha)\
**Post date:** [May 31, 2013, 10:11pm UTC](https://discuss.gradle.org/t/cannot-overwrite-compilejava-task-in-1-7-nightly/2156/3 "2013-05-31T22:11:00Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [June 1, 2013, 12:02am UTC](https://discuss.gradle.org/t/cannot-overwrite-compilejava-task-in-1-7-nightly/2156/4 "2013-06-01T00:02:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kiran\_Anantha](https://avatars.discourse-cdn.com/v4/letter/k/eb8c5e/32.png) [@Kiran\_Anantha](https://discuss.gradle.org/u/Kiran_Anantha)\
**Post date:** [June 2, 2013, 4:16pm UTC](https://discuss.gradle.org/t/cannot-overwrite-compilejava-task-in-1-7-nightly/2156/5 "2013-06-02T16:16:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [June 2, 2013, 4:19pm UTC](https://discuss.gradle.org/t/cannot-overwrite-compilejava-task-in-1-7-nightly/2156/6 "2013-06-02T16:19:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [June 2, 2013, 8:53pm UTC](https://discuss.gradle.org/t/cannot-overwrite-compilejava-task-in-1-7-nightly/2156/7 "2013-06-02T20:53:00Z")

</div>

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)
