Skip to content

jbake-org/jbake-gradle-plugin

Repository files navigation

JBake plugin for Gradle

Build Status Coverage Status Apache License 2 Gradle Plugin Portal, link=


This plugin allows rendering a site using JBake directly from Gradle.

Requirements

  • Java 8

  • Gradle 6+

Examples

A few of the sites that use the plugin and serve as a good example are:

Usage

This is work in progress

plugins {
    id 'org.jbake.site' version '5.5.0'
}

This will add a bake task to your build, which will search for a standard JBake source tree in src/jbake and generate content into $buildDir/jbake (typically build/jbake).

Warning
versions prior to 1.0.0 had a task named jbake. This task has been renamed to bake since 1.0.0.

Init

You can initialise the project structure by running the following command:

gradle bakeInit

The default template is set to groovy. You may change this setting by updating the template property of the jbake configuration. Accepted values are freemarker, groovy, groovy-mte, thymeleaf`, jade.

Alternatively you may define a value for templateUrl that points to a custom template, for example

bakeInit {
    templateUrl = 'http://server.acme.com/path/to/template.zip'
}

Previewing

You can preview your content by running the following command:

gradle bake bakePreview

This will start up a jetty container and serve your baked site on http://localhost:8080 by default. You can change the port by adding this to your build file.

bakePreview {
    port = '8090'
}

The bakePreview task is configured to server the output of the bake task. Should you need to render a different set of files then specify a value for the input property, like so

bakePreview {
    input = project.file('path/to/content')
}

Configuration

Plugin configuration

The default input and output directories can be changed using the jbake configuration block:

jbake {
    srcDirName  = 'jbake-sources'
    destDirName = 'output'
}

The generated output can then be found at $buildDir/output.

The Version could be changed too:

jbake {
    version  = '2.6.5'
}

The default is 2.6.7.

Render Engine configuration

Jbake uses several engines. The library versions could be changed too:

jbake {
    pegdownVersion = '1.6.0'
    flexmarkVersion = '0.62.2' // since jbake 2.6.0
    freemarkerVersion = '2.3.31'
    groovyTemplatesVersion = '3.0.7'
    jade4jVersion = '1.2.7'
    thymeleafVersion = '3.0.12.RELEASE'
    pebbleVersion = '3.1.5' // since jbake 2.6.5
    asciidoctorJavaIntegrationVersion = '0.1.4' //pre jbake 2.3.1
    asciidoctorjVersion = '2.4.3' //since jbake 2.3.1
    jettyVersion = '9.4.36.v20210114'
}

Notice the asciidoctorJavaIntegrationVersion and asciidoctorjVersion. Since Version 2.3.1 jbake has changed to the asciidoctorj library.

This plugin handles this change internally. If you use a Version > 2.3.0 of jbake, the dependency switch to the new one.

Since Version 2.6.0 jbake uses flexmark as replacement for pegdown.

JBake configuration

There are several options to configure JBake. One is to have the regular jbake.properties file into the source directory. The other is to use the plugin configuration block:

jbake {
   configuration['template.post.file'] = 'mypost.ftl'
}