asciidocで書いたドキュメントをgradleでpdfにビルドする設定
adocで書いていたドキュメントをgradleでpdfにビルドできるように色々やりました。今回のミソはjrubyのgradle pluginを使うとgemを使えるようになるということです。
asciidoctorのプラグインと依存関係のgemを使えるようにするために、次のプラグインをプロジェクトルートのbuild.gradleのdependenciesに追記する。
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.9.2' classpath 'com.github.jruby-gradle:jruby-gradle-plugin:1.6.0'
gemを読み込んだりasciidoctorタスクの設定を行ったりする。PlantUMLで図を描いているので、これをPDFに入れるためにasciidoctor-diagramを入れている。これの画像を出力するディレクトリをちゃんと指定しないとPDFに正しく画像が差し込まれない。いい感じのディレクトリレイアウトを知りたい。
また、日本語環境で改行をいい感じにするためにasciidoctor-pdf-cjkを入れている。
apply plugin: 'org.asciidoctor.convert' apply plugin: 'com.github.jruby-gradle.base' dependencies { gems 'rubygems:asciidoctor-diagram:1.5.9' gems 'rubygems:asciidoctor-pdf:1.5.0.alpha.16' gems 'rubygems:asciidoctor-pdf-cjk:0.1.3' } asciidoctor { dependsOn jrubyPrepare requires = [ 'asciidoctor-diagram', 'asciidoctor-pdf-cjk' ] gemPath = jrubyPrepare.outputDir sourceDir = file('docs') sources { include 'toc.adoc' } backends = ['pdf'] outputDir = file('docs/output') separateOutputDirs = false attributes = [ 'imagesoutdir': 'art', // docs ディレクトリから見た相対パス 'imagesdir': 'art' ] }