Configuring a publication

Main configuration blocks

  • Groovy

asciidoc {
  publications {
    main {
        sourceSet {
          sources { (1)
          }
          resources { (2)
          }
          attributes { (3)
          }
          languages { (4)
          }
        }
        output 'asciidoctorj', 'html' (5)
        output 'asciidoctorj', 'pdf'
    }

  }
}
1 Customise asciidoc sources to be processed.
2 Additional resources, such as images.
3 Use attributes block to configure Asciidoc attributes.
4 Human-language additional configuration.
5 Configures the outputs for this publication. The format is toolchainName, outputFormat. See Configuring Toolchains for more info.

Sources and resources

  • Groovy

asciidoc {
  publications {
    main {
        sourceSet {
            sources {
              include 'foo.adoc', 'star*.adoc' (1)
            }
            resources { (2)
              from 'images', {
                include '*.png'
              }
            }
            sourceDir = 'src/docs/asciidoc' (3)
        }
    }
  }
}
1 A list of file patterns for files to include. If nothing is set, all asciidoc documents are included. It uses an Ant-style PatternSet.
2 Configures a copy specification for resources. These are files, such as images, that are required as part of publication, but not processed by an Asciidoctor engine.
3 It is possible to override the source directory, although the convention of src/docs/asciidoc<PUBLICATION> should suffice for most cases.

Asciidoc attributes

asciidoc {
  publications {
    main {
      sourceSet {
          attributes {
              replaceAll 'source-language': 'java' (1)
              add 'source-language': 'java', 'project-version' : '1.2.3' (2)
              add 'source-language', 'java' (3)
              add 'publish-time', asTime(LocalTime.now()) (4)
              add 'publish-date', asDate(LocalDate.now()) (5)
              addAttributeProvider { -> [ 'source-language': 'java']} (6)
          }
      }
    }
  }
}
1 Replace all attributes, except those provided by providers with this new set.
2 Add more attributes as a map.
3 Add a single attribute.
4 Add an attribute and force it to be formatted as a time value. Accepts any java.time.* values, or anything string that can be parsed.
5 Add an attribute and force it to be formatted as a date value. Accepts any java.time.* values, or anything string that can be parsed.
6 Add a provider of attributes.

Treating warnings as errors

  • Groovy

asciidoc {
  publications {
    main {
      sourceSet {
        fatalWarnings ~/missing attribute/ (1)
        missingIncludesAreFatal() (2)
      }
    }
  }
}
1 Provide one or more patterns for scanning log messages. These can be strings, regexes, or anything else can be lazy-evaluated to either.
2 Adds the correct pattern for detecting missing include files.

Docinfo

There is some DSL support for configuring docinfo. It is important to note that for any of headIsPrivate, headerIsPrivate and footerIsPrivate, it configures it for ALL the source AsciiDoc file within the source set. It is still possible to override a DSL setting within a single source file.

For people that ustilise a common docinfo directory, setting it via the DSL has the benefit that Gradle’s up-to-date checks can then be used to detect changes.

  • Groovy

asciidoc {
  publications {
    main {
      sourceSet {
        docInfo {
            headIsPrivate = false (1)
            headerIsPrivate = false (2)
            footerIsPrivate = false (3)
            docInfoDir = 'src/docs/docinfo' (4)
        }
      }
    }
  }
}
1 Set whether head is private or not.
2 Set whether header is private or not.
3 Set whether footer is private or not.
4 Configures a common docinfo source directory.
Currently, setting docInfoDir affects all tasks associated with the specific publication where it was set, even those that are no docinfo-aware. For example, if your publication builds both PDF and HTML files, and you change docbook-header.html, then the PDF output will also be rebuilt. This might be rectified in a future release.