Gradle does not generate javadocs

I am writing a build file with Gradle to perform Java build operations. However, Gradle does not create Javadocs for my project. According to the Gradle.org documentation, to implement the Javadocs task in Gradle, you must specify the source path and classpath.

apply plugin: 'java' javadoc { source = sourceSets.main.allJava classpath = configurations.compile } 

However, when I run the gradle javadoc or gradle build , the default folder for javadocs (build \ docs) is never created, so html files are not created for the project. What can I do to fix this?

+7
java javadoc gradle
source share
5 answers

It looks like your directory structure is not the src/main/java standard. If so, then you need to specify the include pattern as part of the include closure, something like this:

 javadoc { source = sourceSets.main.allJava classpath = configurations.compile } include **/your/directory/structure/* 
+2
source share

For various reasons, we created our own classpath in gradle for our java project. Mostly, since we wanted to separate the dependencies from those that were provided at runtime, from those that were not.

So we installed build.gradle as follows

 configurations { providedCompile } dependencies { providedCompile 'provided1', 'provided2 providedCompile 'provided3' compile 'compile1' compile ('compile2') { exclude group: 'unwanted part' } } sourceSets.main.compileClasspath += configurations.providedCompile javadoc.classpath += configurations.providedCompile sourceSets.test.compileClasspath += configurations.providedCompile sourceSets.test.runtimeClasspath += configurations.providedCompile 

We needed to add the final part so that gradle would choose the class path correctly to execute, test and run javadoc.

0
source share

You can write a gradle task of type Javadoc to create javadocs as follows:

  task createJavadocs (type: Javadoc) { source = project.android.sourceSets.main.java.srcDirs options.linkSource true classpath += project.files(project.android.getBootClasspath().join(File.pathSeparator)) failOnError false } 

To create Javadocs, just run this task.

0
source share

If enabling closure does not work, add a sourceSet closure with srcDir pointing to the module / java directory.

Below is an example of work for me. Here the java directory is src / main / java where I have all my packages.

 sourceSets { build { java.srcDir file('src/integrationTest/java') } } javadoc { source = sourceSets.main.allJava classpath = configurations.compile } 

Running $ gradle javadoc

0
source share

Just to add a little structure to the answers, these are the configs needed to generate Javadoc (using Gradle versions 4 and 5 ).

1. Define your sourceSet (may be optional if using the standard Maven directory structure). Assuming this directory structure:

 β”œβ”€β”€ src β”‚  └── main β”‚  β”œβ”€β”€ java β”œβ”€β”€ src β”‚  └── test β”‚  β”œβ”€β”€ java 

Define sourceSet like this

 sourceSets { main { java { srcDirs =['src/main/java'] } test { java { srcDirs =['src/test/java'] } } 

2. Configure the classpath that will be used when creating javadoc. error: package org.xxxx do this will result in errors similar to the following: error: package org.xxxx does not exist.

Assuming your dependency is defined as follows:

 dependency { compile group: 'xxxx', name: 'yyyy', version: 'zzzz' testCompile group: 'aaaa', name: 'bbbb', version: 'cccc' } 

define a javadoc task this way

 tasks.withType(Javadoc){ source = sourceSet.main.java.srcDirs classpath +=configuration.compile destinationDir = reporting.file("myJavaDoc") //optional } 

If you want to create a Java document for testing, the task will look like this:

 tasks.withType(Javadoc){ source = sourceSet.test.java.srcDirs classpath +=configuration.compile classpath +=configuration.testCompile destinationDir = reporting.file("myJavaDoc") //optional } 
0
source share

All Articles