dokka icon indicating copy to clipboard operation
dokka copied to clipboard

Make it easier to generate KDoc only for Kotlin code in Java + Kotlin projects

Open sdeleuze opened this issue 8 years ago • 1 comments

We have spent a lot of time to configure Dokka in Spring and Reactor project to make it possible to generate only KDoc for Kotlin code while keeping Java classes in the classpath to avoid bloating the output with errors about classes not being available.

Our configuration in Reactor is for example:

task dokka(type: org.jetbrains.dokka.gradle.DokkaTask) {
	dependsOn jar
	group = "documentation"
	description = "Generates Kotlin API documentation."
	moduleName = "reactor-core"
	jdkVersion = 8

	outputFormat = "html"
	outputDirectory = new File(project.buildDir, "docs/kdoc")

	//this is needed so that links to java classes are resolved
	doFirst {
	  classpath += project.jar.outputs.files.getFiles()
	  classpath += project.sourceSets.main.compileClasspath
	}
	//this is needed so that the kdoc only generates for kotlin classes
	//(default kotlinTasks sourceSet also includes java)
	kotlinTasks {
	}
	processConfigurations = []
	sourceDirs = files("src/main/kotlin")
  }

It maybe could help to provide a flag to use only Kotlin sources in the generated KDoc while using all the project classpath.

sdeleuze avatar Sep 22 '17 06:09 sdeleuze

I believe this can be done via gradle configuration, for instance by checking for kotlin plugin presence. Something similar has been done by the spring framework: https://github.com/spring-projects/spring-framework/blob/5378572b00d5b9bc6978d117359b059412773288/build.gradle#L273

Which results in Dokka documentation generated only for Kotlin sources: https://docs.spring.io/spring-framework/docs/current/kdoc-api/

configure([rootProject] + javaProjects) { project ->
	pluginManager.withPlugin("kotlin") {
		apply plugin: "org.jetbrains.dokka"
		apply from: "${rootDir}/gradle/docs-dokka.gradle"
                ..
         }
         ...
}

IgnatBeresnev avatar Apr 27 '22 17:04 IgnatBeresnev

We have achieved that via sourceRoots.setFrom(file("src/main/kotlin")).

sdeleuze avatar Mar 09 '23 10:03 sdeleuze