Solutions above don't work for script gradle plugins (only for binary gradle plugins)
I implemented my own solution for support Dokka in script gradle plugins.
For Android Java/Kotlin Projects:
task androidDokka(type: Exec) {
downloadFile('https://jcenter.bintray.com/org/jetbrains/dokka/dokka-fatjar/0.9.17/dokka-fatjar-0.9.17.jar', 'dokka-fatjar.jar')
def srcDirsNumber = android.sourceSets.main.java.srcDirs.size()
def classpathNumber = android.getBootClasspath().size()
def classpath = (classpathNumber > 0) ? android.getBootClasspath()[0] : ''
def javaAPISpecificationLink = getJavaAPISpecificationLink()
if (srcDirsNumber > 0) {
commandLine 'java', '-jar', "$buildDir/download/dokka-fatjar.jar",
android.sourceSets.main.java.srcDirs[0],
(srcDirsNumber == 2) ? android.sourceSets.main.java.srcDirs[1] : '',
(srcDirsNumber == 3) ? android.sourceSets.main.java.srcDirs[2] : '',
'-output', "$buildDir/javadoc", '-format', 'javadoc',
(classpathNumber > 0) ? '-classpath' : '', (classpathNumber > 0) ? classpath : '',
'-links', "https://developer.android.com/reference/^${android.sdkDirectory}/docs/reference/^${javaAPISpecificationLink}"
} else {
commandLine 'java', '-jar', "$buildDir/download/dokka-fatjar.jar"
}
}
task androidDokkaJar(type: Jar, dependsOn: androidDokka) {
classifier = 'javadoc'
from "$buildDir/javadoc"
}
For Other Java/Kotlin Projects (not Android):
task coreDokka(type: Exec) {
downloadFile('https://jcenter.bintray.com/org/jetbrains/dokka/dokka-fatjar/0.9.17/dokka-fatjar-0.9.17.jar', 'dokka-fatjar.jar')
def srcDirsNumber = sourceSets.main.java.srcDirs.size()
def javaAPISpecificationLink = getJavaAPISpecificationLink()
if (srcDirsNumber > 0) {
commandLine 'java', '-jar', "$buildDir/download/dokka-fatjar.jar",
sourceSets.main.java.srcDirs[0],
(srcDirsNumber == 2) ? sourceSets.main.java.srcDirs[1] : '',
(srcDirsNumber == 3) ? sourceSets.main.java.srcDirs[2] : '',
'-output', "$buildDir/javadoc", '-format', 'javadoc',
'-links', "${javaAPISpecificationLink}"
} else {
commandLine 'java', '-jar', "$buildDir/download/dokka-fatjar.jar"
}
}
task dokkaJar(type: Jar, dependsOn: coreDokka) {
classifier = 'javadoc'
from "$buildDir/javadoc"
}