我通读了Spring REST Docs的文档,并且能够通过向插件添加另一个执行块,从片段中生成HTML文件,我也可以生成pdf:
<execution>
<id>output-pdf</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>pdf</backend>
<doctype>book</doctype>
<attributes>
<snippets>${project.build.directory}/generated-snippets</snippets>
<icons>font</icons>
<pagenums/>
<toc/>
<idprefix/>
<idseparator>-</idseparator>
</attributes>
</configuration>
</execution>
问题在于,生成的pdf不包含Spring REST文档生成的任何代码片段,而是在其位置:
Unresolved directive in api-doc.adoc - include::{snippets}/request-parts.adoc[]
Unresolved directive in api-doc.adoc - include::{snippets}/response-body.adoc[]
Unresolved directive in api-doc.adoc - include::{snippets}/response-fields.adoc[]
看起来好像找不到片段的位置,因此它们不会被渲染。
答案 0 :(得分:0)
听起来已经很近了。请确保将asciidoctorj-pdf和asciidoctorj作为依赖项添加到asciidoctor-maven-plugin。以下Maven代码段显示了此设置。此配置生成HTML和PDF输出。可以通过删除另一个执行块将其减少为一个。
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.6</version>
<dependencies>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj-pdf</artifactId>
<version>1.5.0-alpha.16</version>
</dependency>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
<version>1.5.6</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
<sourceHighlighter>highlightjs</sourceHighlighter>
</configuration>
</execution>
<execution>
<id>generate-pdf-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>pdf</backend>
<sourceHighlighter>coderay</sourceHighlighter>
</configuration>
</execution>
</executions>
</plugin>
此设置对我有用。我目前没有Gradle示例。