Question about `AntBuilder`: Suppose I have a plug...
# plugin-development
k
Question about `AntBuilder`: Suppose I have a plugin that basically does this:
Copy code
fun AntBuilder.taskdef(name: String, classname: String, classpath: Configuration) = withGroovyBuilder {
  "taskdef"("name" to name, "classname" to classname, "classpath" to classpath.asPath)
}

class MyPlugin : Plugin<Project> {
  override fun apply(project: Project) {
    val configuration = ...
    project.ant.taskdef("someTask", "someClass", configuration)
  }
}
Now, suppose I have a task that does this:
Copy code
abstract class MyTask : DefaultTask() {
  @TaskAction
  fun run() {
    ant.withGroovyBuilder {
      // something with "someTask"
    }
  }
}
Would that be well-formed, or do I need to apply the
taskdef
in
MyTask
- ie. introduce a
@Classpath
property?
v
I guess this also depends on whether you want to be configuration-cache safe. As the plugin apply code is part of configuration, I'd expect that construct to fail latest when tried to use with configuration-cache.
k
I was worried more about whether
project.ant
and
task.ant
is shared in some way.
v
If you just navigate into
task.ant
you will see that it calls
project.ant
, so ...
e
https://github.com/gradle/gradle/issues/22041 is the most relevant issue I see (although honestly that looks like some weird Groovy thing)
k
o_O That answers questions, but is disturbing in its own right.
v
Hopefully that gets resolved together with https://github.com/gradle/gradle/issues/1157, so that you can use ant builder in various places where you currently need ugly work-arounds