How to use "ant.replaceregexp" in gradle plugin


I’m writing a gradle plugin as a standalone project using java (not groovy or kotlin).
In groovy gradle you can write ant.replaceregexp.
In kotlin gradle you can write (i think) ant.withGroovyBuild { “replaceregexp” … }

But how can you write the same thing using Java?

ant is probably getAnt(). But i haven’t gotten any further. There is no replaceregexp or withGroovyBuild function on class AntBuilder.