Replacing tasks (overwrite: true) does not work in 1.5

(drf) #1

Using the following sample build.gradle script that worked in gradle 1.4, but fails in 1.5:

apply plugin: 'java'
  task compileJava(type: MyCompileJavaTask, overwrite: true) {
  sourceSet sourceSets.main
  configuration configurations.compile
  println "### USING MyCompileJavaTask instead of default compileJava"
    class MyCompileJavaTask extends DefaultTask {
  def sourceSet
  def configuration
    public void setConfiguration(configuration) {
    this.configuration = configuration
    dependsOn configuration.getTaskDependencyFromProjectDependency(true, "jar")
  public FileCollection getClasspath() {
  public FileCollection getSources() {
  public File getDestinationDir() {
  def compile() {
    println "### TODO Executing my own Java compilation task"
  task printCompileJavaType << {
  println("### compileJava type now: ${compileJava.getClass().toString()}")
  compileJava.dependsOn printCompileJavaType

If you run task


, then the output is

### USING MyCompileJavaTask instead of default compileJava
### compileJava type now: class MyCompileJavaTask_Decorated
### TODO Executing my own Java compilation task

as expected. If you run task


(or any other task that depends on the replaced


task directly or indirectly), then the output is

### USING MyCompileJavaTask instead of default compileJava
:task-overwrite:processResources UP-TO-DATE

which is incorrect. The dependant tasks originally created by the java plugin still use the original



Are there any ways of working around this, other than manually setting the dependencies of all the directly dependant tasks (horrible solution)? Any help is greatly appreciated, -feri

(Peter Niederwieser) #2

As things are today, ‘overwrite: true’ doesn’t give any guarantees about what happens to task dependencies on the original task. A potential alternative is to only overwrite the task action. Why are you overwriting ‘compileJava’ in the first place?

(drf) #3

Hello, and thanks for your reply.

Our problem, of course, is the AspectJ problem already reported elsewhere .

How does one overwrite task actions?

(drf) #4

Hm, I guess Task.setActions should suffice?

(Peter Niederwieser) #5

Yes. In a build script, you would do something like ‘compileJava { actions = []; doLast { … } }’.

(drf) #6

Okay, overwriting task action works, thanks.

A small suggestion though: can that task overwrite feature be deprecated / removed from API & documentation then?

(Peter Niederwieser) #7

A discussion has been started here: