Gradle Java2HTML plugin
The plugin uses Java2Html Ant task to convert Java (and other) source code (complete files or snippets) to HTML, RTF, TeX and XHTML with syntax highlighting. The task is only available to projects that apply the Java or Groovy plugin.
Usage
To use the Java2HTML plugin, include in your build script:
apply plugin: 'com.bmuschko.java2html'
The plugin JAR needs to be defined in the classpath of your build script. It is directly available on Bintray. Alternatively, you can download it from GitHub and deploy it to your local repository. The following code snippet shows an example on how to retrieve it from Bintray:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-java2html-plugin:2.0.1'
}
}
To define the Java2HTML dependency please use the java2html
configuration name in your dependencies
closure.
dependencies {
java2html 'de.java2html:java2html:5.0'
}
Tasks
The Java2HTML plugin defines the following tasks:
java2htmlConvertCode
: Converts source code files to Java2HTML documentation.java2htmlGenerateOverview
: Generates HTML overview files for Java2HTML documentation.
Extension properties
The Java2HTML plugin defines the following convention properties in the java2html
closure. This closure itself contains two closures for each of the tasks: conversion
and overview
.
In the closure conversion
you can define property values for converting the source code:
srcDirs
: Source directories to look for source code files for conversion (defaults tofile('src/main/java')
for a Java project and tofiles('src/main/java', 'src/main/groovy')
for a Groovy project).destDir
: Destination folder for output of the converted files (defaults tofile('build/docs/java2html')
).includes
: File mask for input files (defaults to**/*.java,**/*.groovy
).outputFormat
: File format for conversion output (defaults tohtml
). Valid values arehtml
,xhtml11
,xhtml
,tex
,rtf
andxml
.tabs
: Width in spaces for a tab character (defaults to 2).style
: Sets the table name for the output style (defaults toeclipse
). Valid values areeclipse
,kawa
andmonochrome
.showLineNumbers
: Show line numbers in conversion output (defaults totrue
).showFileName
: Show the file name in conversion output (defaults tofalse
).showDefaultTitle
: Sets the title of generated html pages (if any) to the relative name of the source file, e.g.de/java2html/Java2Html.java
(defaults to emptyfalse
).showTableBorder
: Show a border around the conversion output (defaults tofalse
).includeDocumentHeader
: Add a document header at the beginning of the output file (defaults totrue
).includeDocumentFooter
: Add a document footer at the end of the output file (defaults totrue
).addLineAnchors
: Add html-anchors to each line for html output (defaults tofalse
).lineAnchorPrefix
: String that will be added as prefix for the line anchors for html output (defaults to''
).horizontalAlignment
: Horizontal alignment of the output (defaults toleft
). Valid values areleft
,center
andright
.useShortFileName
: Use short (ClassName.html
) or long (ClassName.java.html
) filenames for output (defaults tofalse
).overwrite
: Overwrite existing files even if the destination files are newer (defaults tofalse
).
In the closure overview
you can define property values for generating the HTML overview files:
srcDirs
: Source directories to look for generated files by Java2HTML (defaults tofile('build/docs/java2html')
of all modules in project).destDir
: Destination folder for HTML overview files (defaults tofile('build/docs/java2html')
).pattern
: Java2HTML file pattern to be included in HTML overview (defaults to**/*.html
).windowTitle
: Window title in overview (defaults to project name).docTitle
: Document title in overview (defaults to project name).docDescription
: Document description in overview.icon
: Icon file to be use in overview.stylesheet
: CSS stylesheet file to be use in overview (defaults to JavaDoc stylesheet).
Example
java2html {
conversion {
tabs = 4
style = 'eclipse'
showFileName = true
useShortFileName = true
override = true
showDefaultTitle = true
}
overview {
docDescription = 'Gradle plugin for turning source code into HTML, RTF, TeX and XHTML using Java2HTML.'
}
}