Search code examples
xmlpdfgradledocbookmultiplatform

Generate PDF from docbook XML when building Java project using Gradle


I need to generate a PDF version of the docbook.xml documentation (5.0) when building the java project using gradle (build.gradle file).

If someone could show an example of a script that will work on any platform (Mac OS X, Windows, Linux) that would be very helpful.


Solution

  • Ok, so finally I found the solution. In order to generate a PDF, you have to provide the following files :

    You have to add after to build.gradle the line

    apply from: "docbook.gradle"
    

    after

    apply plugin: "java"
    

    Then, append to the end of build.gradle this:

    docbookPdf {
        sourceFileName = "docbook.xml"
        stylesheet = file("doc/docbook-style.xsl")
        sourceDirectory = file( "doc" )
        docsDir = new File(project.getBuildDir(), "docs");
    }
    

    Here, we've put the docbook.xml and docbook-style.xsl in rootDirectory/doc, and we put the generated PDF in rootDirectory/docs (/pdf).

    Here is an example of a docbook stylesheet that you can use: http://cl.ly/2n1p3o0r1L3Z1d2U4345

    To generate the PDF, from the terminal, go to the directory where the file build.gradle is and execute

    gradle docbookPdf
    

    if you named the task 'docbookPdf'.

    That's it. It should work on any platform.