Ant task java.util.zip.ZipException: error in opening zip file

I’m running the ant xjc task to generate classes from a schema file and ant is trying to unpack all the non-jar resources on the classpath giving me 1000s of " java.util.zip.ZipException: error in opening zip file" errors. This has only started happening recently although I can’t remember with which Gradle version it started.

Is it possible to configure the ant task to ignore these files?

task generateRm() {
    description 'Generate RM classes from schema'
    def jaxbTargetDir = new File(generatedSrcDir)
      doLast {
        ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: configurations.compile.asPath)
        ant.jaxbTargetDir = jaxbTargetDir
          ant.xjc(destdir: '${jaxbTargetDir}', package: 'com.mvr.business.portal.rm.enquiries', extension: true) {
            schema(dir: 'src/main/resources/schema/rm', includes: 'rm_schema.xsd')
            binding(dir: 'src/main/resources/schema/rm', includes: 'rm-bindings.xjb')
        }
    }
    generateRm.outputs.dir jaxbTargetDir
}
:generateRm
Unable to obtain resource from /Users/phill/.gradle/caches/modules-2/files-2.1/org.apache.wicket/wicket/6.14.0/528ab2deef2e48dfaa4af0fbfbd6e5404659932f/wicket-6.14.0.pom: java.util.zip.ZipException: error in opening zip file
[ant:xjc] Unable to obtain resource from /Users/phill/.gradle/caches/modules-2/files-2.1/org.apache.wicket/wicket/6.14.0/528ab2deef2e48dfaa4af0fbfbd6e5404659932f/wicket-6.14.0.pom:
[ant:xjc] java.util.zip.ZipException: error in opening zip file
[ant:xjc]
at java.util.zip.ZipFile.open(Native Method)

I ran into the same issue. It seems that com.sun.tools.xjc.XJCTask has issues when executed concurrently. It seems that using com.sun.tools.xjc.XJC2Task instead seems to fix it.