Is it possible to do in-place filtering?

Hi guys,

I’m looking for a way to post-process generated documentation files (as a workaround for a missing asciidoctor feature). For that, I’m trying to use the Copy task to filter resources. Here’s what my task looks like:

task createJavadocLinks(type:Copy) {
    description = 'Filters generated documentation to generate links to javadoc'
    from asciidoctor.outputDir
    into asciidoctor.outputDir
    filter { line ->
        line.replaceAll(/gapi::([a-zA-Z0-9$.]+)/) { m->
            // ... snip ...
  asciidoctor.finalizedBy createJavadocLinks

The problem is that the source files are also the target files, so there’s a conflict and the resulting file is empty. I’d like to avoid having a separate output directory with the postprocessed files, so the question is simple: is there any way to do in-place filtering?


You may have to do the in-place filtering with plain Groovy. It should probably go into ‘asciidoctor.doLast {}’. Otherwise, the ‘asciidoctor’ task will always be out-of-date, because the subsequent in-place filtering task keeps changing its outputs.

I see… Thanks for the answer!