asciidoctor / asciidoctor-gradle-plugin

A Gradle plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
https://asciidoctor.github.io/asciidoctor-gradle-plugin/
Apache License 2.0
285 stars 120 forks source link

Avoid copying resources to PDF backend output directory #569

Open k-mack opened 4 years ago

k-mack commented 4 years ago

When the PDF backend is specified, resources are unnecessarily copied to its output directory. The build script below is enough to reproduce this behavior. As desired, the images directory will be copied to the HTML5 output directory; but it will also be copied to the PDF output directory, which is unnecessary since the images are embedded in the PDF document.

plugins {
    id 'org.asciidoctor.jvm.convert' version '3.2.0'
    id 'org.asciidoctor.jvm.pdf' version '3.2.0'
}

repositories {
    jcenter()
}

asciidoctorj {
    attributes imagesdir: 'images'
}

asciidoctor {
    baseDirFollowsSourceDir()
    resources {
        from 'src/docs/asciidoc/images'
        into './images'
    }
    outputOptions {
        backends = ['html5', 'pdf']
    }
}

Full reproducer here: https://github.com/k-mack/asciidoctor-gradle-plugin-pdf-images-dir

The workaround is to create separate tasks: one to create the HTML document and one to create the PDF document.

ysb33r commented 4 years ago

That is intended behaviour. You should use the the asciidoctorPdf task for generating PDFs as it is optimised.

You can have a lot of common behaviour configured via the global asciidoctorj extension. Failing that you can also use tasks.withType<AbstractAsciidoctorTask>, but in that case rememeber to add an import to the build file.

k-mack commented 4 years ago

@ysb33r thanks for clarifying. I'll continue to use different tasks for the HTML and PDF backends. Perhaps a future version could log a warning/informational message when resources {} and the pdf backend is used with the general-purpose asciidoctor task to encourage this pattern.

(To be fair, the documentation does speak to this: https://github.com/asciidoctor/asciidoctor-gradle-plugin/blame/85878d8/docs/src/docs/asciidoc/parts/asciidoctorj-pdf-plugin.adoc#L28).