Failling UP-TO-DATE check on overwritten task

I replaced the default compileJava task with a custom one to use the aspectj compiler. It seams like the overwritten compileJava task is executed twice, so each UP-TO-DATE check fails.

I’m getting the following two messages: 1. Task ‘:someProject:compileJava’ has changed type from ‘org.gradle.api.tasks.compile .JavaCompile_Decorated’ to ‘org.gradle.api.DefaultTask_Decorated’.

  1. Executing task ‘:someProject:compileJava’ due to:

Output file xyz has changed.

The tasks looks like this:

task compileJava(overwrite: true, dependsOn: [someOtherTask, configurations.compile.getTaskDependencyFromProjectDependency(true, "jar")]) {
 inputs.file sourceSets.main.allJava
    outputs.dir sourceSets.main.output.classesDir
 doLast {
  ant {
   taskdef(name: 'iajc',
     classname: 'org.aspectj.tools.ant.taskdefs.AjcTask',
     classpath:"${configurations.compile.asPath}")
   iajc(maxmem: "256m", fork: "true", source: "1.6", target: "1.6", srcdir: "${projectDir}/java", destdir: "${projectDir}/build/classes/main", debuglevel: "lines,vars,source", classpath:configurations.compile.asPath )
  }
 }
}

Why is the task executed twice, shouldn’t the task with overwrite property set to true replace the original compileJava task? I’m getting this error since updating from gradle 1.4 to 1.6.

The behavior after overwriting a task isn’t well-defined (known issue). It’s probably better to replace the task action.

Thanks Peter. This way it works.