To generate Javadoc documentation, we must use the javadoc
task that is of type org.gradle.api.tasks.javadoc.Javadoc
. The task generates documentation for the Java source files in the main
source set. If we want to generate documentation for the source sets in our project, we must configure the javadoc
task or add an extra javadoc
task to our project.
Note that, in our project, we have an api
and main
source set with the Java source files. If we want to generate documentation for both the source sets, we have to configure the javadoc
task in our project. The source
property of the javadoc
task is, by default, set to sourceSets.main.allJava
. If we add sourceSets.api.allJava
to the source
property, our interface file is also processed by the javadoc
task:
apply plugin: 'java' ... javadoc { source sourceSets.api.allJava } ...
Next, we can run the javadoc
task, and the documentation is generated and put into the build/docs/javadoc
directory:
$ gradle javadoc :compileApiJava UP-TO-DATE :processApiResources UP-TO-DATE :apiClasses UP-TO-DATE :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :javadoc BUILD SUCCESSFUL Total time: 3.425 secs
We can set more properties on the
javadoc
task. For example, we can set a title for the generated documentation with the title
property. The default value is the name of the project followed by the project version number, if available.
To change the destination directory, we can set the destinationDir
property of the javadoc
task to the directory we want.
We can also use the options
property to define a lot of properties we know from the Java SDK javadoc
tool. The following example shows how we can set some of the options for the javadoc
task in our project:
apply plugin: 'java' ... javadoc { source sourceSets.api.allJava title = 'Gradle Sample Project' options.links = ['http://docs.oracle.com/javase/6/docs/api/'] options.footer = "Generated on ${new Date().format('dd MMM yyyy')}" options.header = "Documention for version ${project.version}" } ...
3.146.37.250