gradleasciidocasciidoctorasciidoctor-pdf

asciidoctorj-pdf produces ArrayIndexOutOfBoundsException when more than one backends are defined


I use gradle with asciidoctor-gradle-plugin to produce documentation in varioius formats. My build.gradle looks like:

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
      classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.9.2'
      classpath 'org.asciidoctor:asciidoctorj-diagram:1.5.0'
      classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16'
   }
}

apply plugin: 'java'
apply plugin: 'org.asciidoctor.convert'


asciidoctorj {
    version = '1.6.0'
}

asciidoctor {
    resources{
        from('src/images')
        into './images'
    }
    backends 'pdf', 'docbook', 'html5'
    requires 'asciidoctor-diagram'
    sourceDir = file('src/')
    outputDir = file('build/')
    attributes \
        'imagesoutdir': "./images"
}

When asciidoctor task is run I get the error:

10:09:08 AM: Executing task 'asciidoctor'...

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at org.asciidoctor.internal.EnvironmentInjector.inject(EnvironmentInjector.java:31)
    at org.asciidoctor.internal.JRubyAsciidoctor.injectEnvironmentVariables(JRubyAsciidoctor.java:142)
    at org.asciidoctor.internal.JRubyAsciidoctor.createJRubyAsciidoctorInstance(JRubyAsciidoctor.java:129)
    at org.asciidoctor.internal.JRubyAsciidoctor.create(JRubyAsciidoctor.java:82)
    at org.asciidoctor.Asciidoctor$Factory.create(Asciidoctor.java:726)
    at org.asciidoctor.gradle.backported.AsciidoctorJavaExec.getAsciidoctorInstance(AsciidoctorJavaExec.groovy:73)
    at org.asciidoctor.gradle.backported.AsciidoctorJavaExec.run(AsciidoctorJavaExec.groovy:39)
    at org.asciidoctor.gradle.backported.AsciidoctorJavaExec.main(AsciidoctorJavaExec.groovy:195)
:asciidoctor FAILED

The strange part is the error disappears when backends is set to exactly one

backends 'pdf'

Does anybody know how to fix it?


Solution

  • As a workaround you can try using older version of asciidoctor-gradle-plugin e.g.

    org.asciidoctor:asciidoctor-gradle-plugin:1.5.8
    

    Im not exactly sure what's the difference between those versions but 1.5.8 seems to work for me.