I am using an Ant method from an external JAR in a Gradle build, and I can’t work out how to get it to work with the configuration cache enabled. Is this possible, or is it something that isn’t compatible with the configuration cache (as warned about here)?
In more detail, I am pulling in the Ant task like this:
ant.withGroovyBuilder {
"taskdef"( "name" to "xmlbean",
"classname" to "org.apache.xmlbeans.impl.tool.XMLBean",
"classpath" to xbeanconf.asPath )
}
as documented in the XMLBeans documentation for the Ant task
I am defining a custom Gradle task type that makes use of this task:
abstract class ScompJar: Scomp() {
@get:OutputFile
abstract val jar: RegularFileProperty
@TaskAction
fun execute() {
ant.withGroovyBuilder {
"xmlbean"( "srcgendir" to srcgendir.asFile.get(),
"classgendir" to classgendir.asFile.get(),
....
and registering a task of this type like this:
val scompSimple = tasks.register<ScompJar>("scompSimple") {
....
Without the configuration cache, this works perfectly, and has done over several previous versions of Gradle. With the configuration cache enabled, I get an error like this:
> Problem: failed to create task or type xmlbean
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
I’m guessing that this is because in the serialisation of the task’s state in the configuration cache, the Ant task “xmlbean” defined in the project’s AntBuilder is no longer visible to the task (but maybe I’m wrong here).
I have tried a number of ways of trying to get the xmlbean task definition into the task type, but so far I have not found an approach that works, and this is all some way outside my comfort zone. Is what I am trying to possible, and does anyone have any suggestions about how to do it? I am using Gradle 9.5.1.