dokka icon indicating copy to clipboard operation
dokka copied to clipboard

Gradle plugin v2 with versioning plugin requires olderVersionsDir to exist

Open jeffdgr8 opened this issue 11 months ago • 2 comments

Describe the bug With the Dokka Gradle plugin v2, using the versioning plugin and configuring olderVersionsDir to a directory path that doesn't currently exist, the task :dokkaGeneratePublicationHtml fails with the error:

A problem was found with the configuration of task ':dokkaGeneratePublicationHtml' (type 'DokkaGeneratePublicationTask').

  • In plugin 'org.jetbrains.dokka.gradle.DokkaBasePlugin_Decorated' type 'org.jetbrains.dokka.gradle.tasks.DokkaGeneratePublicationTask' property 'generator.pluginsConfiguration.versioning$1.olderVersionsDir' specifies directory '.../docs/older' which doesn't exist.

This was not an error before the v2 Gradle plugin.

Expected behaviour My project configures the :dokkaGeneratePublicationHtml task with a doFirst lambda that moves the older version directory to the configured path. So the files are present when the task runs, but not before it runs.

It should not be an error to configure this path to a currently non-existent directory. It's undesirable to have the empty directory exist in the file system when the code expects it to only exist temporarily while the API docs are being generated.

To Reproduce Configure a project with the versioning plugin and set olderVersionsDir to a non-existent path. Then run :dokkaGenerate to see the error.

Dokka configuration Configuration of dokka used to reproduce the bug

dependencies {
    dokkaPlugin(libs.dokka.versioning)
}

tasks.dokkaGeneratePublicationHtml {
    dokka.pluginsConfiguration.versioning {
        olderVersionsDir = projectDir.resolve("some/non-existent/dir")
        // ...
    }
}

Installation

  • Operating system: macOS
  • Build tool: Gradle v8.11.1
  • Dokka version: 2.0.0

Additional context Reproducible with my library, Kotbase by removing this line of code: tempOlderDir.mkdir() (check out commit af4ec9f).

jeffdgr8 avatar Dec 19 '24 08:12 jeffdgr8

Thanks for the report, this looks like something that we can fix easily by replacing @InputDirectory with @InputFiles.

https://github.com/gradle/gradle/issues/2016#issuecomment-965126604

https://github.com/Kotlin/dokka/blob/623ee350ad054f7bd893cf03348fd10781fe0903/dokka-runners/dokka-gradle-plugin/src/main/kotlin/engine/plugins/DokkaVersioningPluginParameters.kt#L68-L71

adam-enko avatar Dec 19 '24 13:12 adam-enko

I worked around this issue by switching up the logic for where the olderVersionsDir and outputDirectory are. Instead of moving the older versions to a temp directory and outputing to the final API docs location, I use the API docs' older versions from the existing location and output the new API docs to the default build directory location. Then I move the docs from the build directory to replace the previous docs. This way, the olderVersionsDir will already exist.

jeffdgr8 avatar Dec 22 '24 07:12 jeffdgr8