Kotlin / dokka

API documentation engine for Kotlin
https://kotl.in/dokka
Apache License 2.0
3.43k stars 409 forks source link

Print the path to the HTML files after generation #2680

Open CLOVIS-AI opened 2 years ago

CLOVIS-AI commented 2 years ago

Is your feature request related to a problem? Please describe When I run ./gradlew dokkaHtmlMultiModule, I often want to open the files in a browser. Currently, I have to run <browser> build/dokka/htmlMultiModule/index.html, which is inconvenient and unfriendly for newcomers to the project.

Describe the solution you'd like When Dokka is done building the project, it prints a file:// path to the generated index.html file. Smart displays (the IDEA's console, emulators like KDE's Konsole) automatically replace it by an hyperlink that the user can click to open the file in their browser.

Describe alternatives you've considered I guess it could be possible to open the file in the browser directly or introduce a task dokkaOpenBrowser but that seems like more trouble than it's worth, especially when paths in file:// seem well supported.

Additional context This seems to be a common solution to this problem.

For example, the integrated test task in Gradle:

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///home/[REDACTED]/build/reports/tests/jvmTest/index.html

As another example, JetBrains' Kover:

> Task :koverMergedHtmlReport
Kover: merged HTML report file:///home/[REDACTED]/build/reports/kover/html/index.html

Are you willing to provide a PR? I'm not familiar with Gradle plugins nor with Dokka's codebase, but this seems like a trivial feature (it's just printing out the path that Dokka writes to). With an outline of where to look and what to change, I can provide a PR.

IgnatBeresnev commented 1 year ago

In the meantime, it could be achieved by configuring Dokka's tasks:

import org.jetbrains.dokka.gradle.DokkaTask

plugins {
    id("org.jetbrains.dokka")
}

tasks.withType<DokkaTask>().configureEach {
    doLast {
        println("Documentation generated to ${outputDirectory.get()}")
    }
}

Output:

$ ./gradlew clean dokkaHtml

> Task :dokkaHtml
Initializing plugins
Dokka is performing: documentation for dokka-debug-kts
Validity check
Creating documentation models
Transforming documentation model before merging
Merging documentation models
Transforming documentation model after merging
Creating pages
Transforming pages
Rendering
Running post-actions

Documentation generated to /home/{user}/IdeaProjects/{project}/build/dokka/html