mynethome.de

16. November 2016 um 17:28 Uhr

Asciidoctor-Gradle: Separate tasks for PDF and HTML output

Sometimes you want to have simple additional tasks in a build to generate certain output.

A good example is generation of HTML or PDF from Asciidoctor. With the following example you can just do gradle pdf or gradle html to create the desired output – instead of changing the „backends“ property in the build.gradle back and forth.

Have fun ;-)

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
        classpath 'org.asciidoctor:asciidoctorj-diagram:1.5.0'
        classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.11'
        classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
    }
}

apply plugin: 'org.asciidoctor.convert'
apply plugin: 'com.github.ben-manes.versions'

repositories {
    jcenter()
}

asciidoctorj {
    version = '1.6.0-alpha.3'
}

def asciidoctor = {
   requires = ['asciidoctor-diagram']
   sources {
      include 'article.adoc'
    }

    backends = ['html5', 'pdf']

    attributes 'source-highlighter'    : 'coderay',
               'coderay-linenums-mode' : 'table',
               //toc                     : 'left',
               icons                   : 'font',
               linkattrs               : true,
               encoding                : 'utf-8'               
}

task('pdf', type: org.asciidoctor.gradle.AsciidoctorTask){
  configure asciidoctor
  backends = ['pdf']  
}

task('html', type: org.asciidoctor.gradle.AsciidoctorTask){
  configure asciidoctor
  backends = ['html5']  
}

Update: To reuse the settings from a common block, we need to define the config in a variable and use it to configure the tasks with configure as updated in the example. :)

Einen Kommentar schreiben


Gravatar unterstützt

mynethome.de wird erstellt mit WordPress
Beiträge (RSS) und Kommentare (RSS)

(c) 2005 - 2015 Markus Schlichting