Search code examples
junit5asciidoctorspring-restdocs

Spring REST Docs - how to configure asciidoctor task to include generated snippet into index?


I'm having an index.adoc file located in: src/docs/asciidoc/index.adoc

With contents: include::{snippets}/add-measurement/curl-request.adoc[]

When I call build task then generated snippets are here: build/generated-snippets/my-call/*.adoc

But when I look into generated index.html it turns out that snippets are not included:

Unresolved directive in index.adoc - include::{snippets}/add-measurement/curl-request.adoc[]

My asciidoctor task in build.gradle:

asciidoctor {
    dependsOn junitPlatformTest
}

When I add sourceDir snippetsDir to asciidoctor gradle task then every snippet is converted to html but index.html is not generated.


Solution

  • According to your information, snippetsDir is configured and snippets are placed in the expected folder and the AsciiDoctor sourceDir is already correct as an index.html is generated (but with broken includes). So the one thing that seems to be missing is to pass on the snippetDir to AsciiDoctor:

    asciidoctor {
      inputs.dir snippetsDir
      dependsOn junitPlatformTest  
    }
    

    or

    asciidoctor {
      attributes "snippets": snippetsDir
      dependsOn junitPlatformTest  
    }
    

    Examples for working Gradle setups: