Kotlin / dokka

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

[Bug] Dokka Does Not Accept Using Directories for the Includes Property #3863

Open solonovamax opened 1 month ago

solonovamax commented 1 month ago

Describe the Bug

When setting the "includes" for dokka, it will not accept directories.

Expected Behaviour

Directories are accepted when doing

dokka {
    dokkaSourceSets.configureEach {
        includes.from(file("dokka")) // here, dokka is a directory containing multiple markdown files
    }
}

Actual Behaviour

An error is produced when the above code is used.

Environment

Additional Information

The issue here is with the use of FileCollection.getFiles() on this line: https://github.com/Kotlin/dokka/blob/7027da812e8b3120a56830d9790a27f57fa7d27c/dokka-runners/dokka-gradle-plugin/src/main/kotlin/engine/parameters/builders/DokkaSourceSetBuilder.kt#L77

As-per the documentation:

Returns the contents of this collection as a Set. The contents of a file collection may change over time. Note that this method returns File objects that represent locations on the file system. These File objects do not necessarily refer to regular files. Depending on the implementation of this file collection and how it has been configured, the returned set may contain directories, or missing files, or any other kind of file system element.

(emphasis my own)

Also, this same issue will apply to

The solution to this would be to instead use a FileTree:

// files
classpath = spec.classpath.asFileTree.files.toList(),
includes = spec.includes.asFileTree.files,
samples = spec.samples.asFileTree.files,
sourceRoots = spec.sourceRoots.files,
suppressedFiles = spec.suppressedFiles.asFileTree.files,

however, I do believe it would be beneficial to expose suppressedFiles as a ConfigurableFileTree rather than a ConfigurableFileCollection. This is because it allows filtering:

dokka {
    dokkaSourceSets.configureEach {
        suppressedFiles.apply {
            from("src")
            include("**/internal/**")
            exclude("**/api/**")
        }
    }
}

however, this would be a breaking api change. Unsure if breaking api changes would be possible for the beta. I am going to submit a PR that changes it to use a file tree, however.

adam-enko commented 1 month ago

Discussed further in Slack: https://kotlinlang.slack.com/archives/C0F4UNJET/p1729054899938509 (archive)