Skip to content

Instantly share code, notes, and snippets.

@mojavelinux
Last active March 2, 2017 18:00
Show Gist options
  • Save mojavelinux/3f5839d332fd554c46bb020d9170bba8 to your computer and use it in GitHub Desktop.
Save mojavelinux/3f5839d332fd554c46bb020d9170bba8 to your computer and use it in GitHub Desktop.
A Gradle build that generates a versioned PDF for multiple AsciiDoc documents. Separate tasks are used for illustrative purposes and to allow each conversion to be individually configured.
buildscript {
dependencies {
classpath 'org.asciidoctor:asciidoctorj:1.5.4.1'
}
}
plugins {
id 'org.asciidoctor.convert' version '1.5.3'
id 'com.github.jruby-gradle.base' version '1.3.3'
}
dependencies {
gems('rubygems:asciidoctor-pdf:1.5.0.alpha.14') {
exclude module: 'asciidoctor'
exclude module: 'thread_safe'
}
}
asciidoctorj.version '1.5.4.1'
jruby.execVersion '9.1.7.0'
jrubyPrepare.outputDir file(".bundle/gems/jruby/${jruby.execVersion}")
ext.extractVersion = { String filename ->
org.asciidoctor.Asciidoctor.Factory.create().readDocumentHeader(file(filename)).attributes['revnumber'] ?: 'latest'
}
class AsciidoctorPdfTask extends org.asciidoctor.gradle.AsciidoctorTask {}
task documentA(type: AsciidoctorPdfTask, group: 'Documentation', description: 'Generates the PDF for document A.') {
def sourceFile = 'document-a.adoc'
doFirst {
options.to_file = "${sourceFile.take(sourceFile.lastIndexOf('.'))}-v${extractVersion(sourceFile)}.pdf"
}
sources { include sourceFile }
}
task documentB(type: AsciidoctorPdfTask, group: 'Documentation', description: 'Generates the PDF for document B.') {
def sourceFile = 'document-b.adoc'
doFirst {
options.to_file = "${sourceFile.take(sourceFile.lastIndexOf('.'))}-v${extractVersion(sourceFile)}.pdf"
}
sources { include sourceFile }
}
tasks.withType(AsciidoctorPdfTask) {
dependsOn jrubyPrepare
gemPath jrubyPrepare.outputDir
requires 'asciidoctor-pdf'
backends 'pdf'
sourceDir projectDir
resources {}
outputDir buildDir
separateOutputDirs false
}
tasks.remove asciidoctor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment