Running AsciidoctorJ with Spring Boot

Due to Spring Boot’s packaging system, Asciidoctorj won’t work out of the box from a single JAR application. Luckily Spring Boot plugins for Gradle and Maven provide options to fix it.

Below you can find the required configurations to apply to Maven and Gradle. But read about extracting libraries during runtime for the details.

Gradle configuration

You just need to add the following configuration to your Gradle build. This will include not only AsciidoctorJ but others that also require unpacking like asciidoctor-pdf or asciidoctorj-diagram.

bootJar {
	requiresUnpack '**/asciidoctorj-*.jar'
}

Maven configuration

Similarly, for the Maven plugin add the following configuration to your POM. However, unlike in Gradle, wildcards are not allowed and dependencies need to be described one by one.

Run mvn dependency:tree to find all required dependencies, including transitive ones. See this example for a full configuration.
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <requiresUnpack>
            <dependency>
                <groupId>org.asciidoctor</groupId>
                <artifactId>asciidoctorj</artifactId>
            </dependency>
        </requiresUnpack>
    </configuration>
</plugin>