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
286 stars 122 forks source link

Newer Gradle plugins #610

Closed sebersole closed 3 years ago

sebersole commented 3 years ago

I am trying to upgrade from version 1.5 of the Gradle plugin to the newer 3.x versions. So far I have tried

  1. 3.1 which is the latest documentation I could find - https://asciidoctor.github.io/asciidoctor-gradle-plugin/master/user-guide/#options
  2. 3.3 which is the latest version listed on the Gradle Plugin Portal.

And I have tried both org.asciidoctor.jvm.convert and org.asciidoctor.jvm.base

In none of these combinations have I been able to figure out how to specify the backend(s) I want to use. In 1.5, I had:

task renderUserGuide(type: AsciidoctorTask, group: 'Documentation') {
    ...
        backends "html5"
}

The updated documentation for that task (https://asciidoctor.github.io/asciidoctor-gradle-plugin/master/user-guide/#_task_configuration) makes it sound like that same configuration should work:

Properties & methods for configuring generic AsciidoctorTask backends - the backends to use. Use backends to append. Use setBackends or backends=[] to overwrite

However, with both 3.1 and 3.3, this gives:

A problem occurred evaluating project ':documentation'.
> Could not set unknown property 'backends' for task ':documentation:renderGettingStartedGuides' of type org.asciidoctor.gradle.jvm.AsciidoctorTask.
programming-wolf commented 3 years ago

In your task, wrap backends in outputOptions:

outputOptions {
    backends 'html5'
}

That works for us. 🙂

sebersole commented 3 years ago

Thanks @programming-wolf

programming-wolf commented 3 years ago

No worries. Did it solve your problem, @sebersole ? Then we can close this issue. 😺

sebersole commented 3 years ago

I can say for sure it does not work on the asciidoctorj extension, which is a shame since we have 4 different AsciidoctorTasks in our build and they all need this same config -

> No signature of method: documentation_34h71t8h0cewmcb9ayknku8za.asciidoctorj() is applicable for argument types: (documentation_34h71t8h0cewmcb9ayknku8za$_run_closure6) values: [documentation_34h71t8h0cewmcb9ayknku8za$_run_closure6@77b3c35f]

It "works" when applied to the task. "Works" as in it does not blow up. I read that html5 is the default backend and no idea what separateOutputDirs does, so not sure :)

programming-wolf commented 3 years ago

Sorry, I copied that from my project, you can ignore that.

My task looks like this:

class RenderCurriculumTask extends AsciidoctorTask {
    @Inject
    RenderCurriculumTask(WorkerExecutor worker, String curriculumFileName, String versionDate, String language, boolean withRemarks) {
        super(worker)
        sourceDir = new File("./docs/")
        sources {
            include "index.adoc"
            include "${curriculumFileName}.adoc"
        }
        outputDir = new File("./build/")
        outputOptions {
            separateOutputDirs = false
            backends 'pdf', 'html5'
        }
...
sebersole commented 3 years ago

I'm not sure what that is in reference to ;)

You can close this though. As far as I can see, applying to each individual task works.

FWIW you could achieve the same as you do by subclassing by simply iterating all of the AsciidoctorTask instances and applying the commonality. Though maybe you subclass for other reasons...

programming-wolf commented 3 years ago

This was me trying to show how we implemented it and got it working. 🙂

sebersole commented 3 years ago

so ultimately this worked for me...

tasks.withType(AsciidoctorTask).all {
    baseDirFollowsSourceDir()
    outputOptions {
        separateOutputDirs = false
        backends 'html5'
    }
}
sebersole commented 3 years ago

Closing as I got it working with your help. Thanks!