Programmatically replacing task

I have created IAJC task and replacing compileJava with it. My code is –

IAJCPlugin.groovy (custom plug-in)

class IAJCPlugin implements Plugin<Project> {
 void apply(Project project) {
    task compileJava(type: IAJC)


class IAJC extends DefaultTask {
 IAJC () {
  project.configurations { iajcconf }
  project.dependencies {
iajcconf 'org.aspectj:aspectjtools:1.6.2' }
    doFirst {
   ant.taskdef(resource: 'org/aspectj/tools/ant/taskdefs/', classpath: project.configurations.iajcconf.asPath){ dir ->
    if(dir.exists()) {
     ant.iajc( destdir: project.sourceSets.main.output.classesDir,
       source: "1.6",
       srcdir : dir,
       classpath: project.configurations.compile.asPath)


apply plugin: 'iajc' //custom plugin IAJCPlugin

This does not work and I am getting the following error –

Caused by: groovy.lang.MissingMethodException: No signature of method: is applicable for argument types: (java.util.LinkedHashMap) values: [[type:class]]

You can’t use the ‘task compileJava(type: IAJC)’ syntax in a plugin. It’s only valid in a build script. You’ll need to use:

project.task(“compileJava”, type: IAJC), java.lang.String)

Thanks Luke

I have used the following

project.task([type: IAJC, overwrite: true], "compileJava")