Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Dokka 2 #849

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 0.30.0 **UNRELEASED**

- Add support for Dokka 2.0.0-Beta
- Supports `org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled`
- When `pluginMode` is set to `V2EnabledWithHelpers` the old v1 tasks are used
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: in case of V2EnabledWithHelpers we do only create stub tasks which matches old types - they will fail to generate documentation.
Still, it should not really matter, as V2EnabledWithHelpers should only be used during migration and should not be committed or used afterwards

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look at this. I adjusted the v2 detection for the html plugin to be project.extensions.findByName("dokka") != null. That way we a) don't need this part about the migration and b) it fixes a configuration cache issue on our side. 9ecef5c

- Supports both `org.jetbrains.dokka` and `org.jetbrains.dokka-javadoc`
- If both are applied the javadoc output is published
- Removed support for the old `org.jetbrains.dokka-android` plugin
- Remove usages of deprecated Gradle API that is scheduled to be removed in Gradle 9.0
- Raised minimum supported Gradle version

Expand All @@ -23,7 +29,7 @@

Configuration cache is generally supported, except for:
- Publishing releases to Maven Central (snapshots are fine), blocked by [Gradle issue #22779](https://github.com/gradle/gradle/issues/22779).
- Dokka does not support configuration cache
- Dokka only supports configuration cache in `V2Enabled` mode


## 0.29.0 *(2024-06-20)*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,46 @@ class MavenPublishPluginSpecialCaseTest {
assertThat(result).javadocJar().exists()
assertThat(result).javadocJar().containsFiles(ignoreAdditionalFiles = true, "index.html")
}

@TestParameterInjectorTest
fun dokka2() {
val kotlinVersion = KotlinVersion.entries.last()
val original = kotlinJvmProjectSpec(kotlinVersion)
val project = original.copy(
plugins = original.plugins + dokka2Plugin,
basePluginConfig = original.basePluginConfig.replace("JavadocJar.Empty()", "JavadocJar.Dokka(\"dokkaGeneratePublicationHtml\")"),
)
val result = project.run(fixtures, testProjectDir, testOptions)

assertThat(result).outcome().succeeded()
assertThat(result).artifact("jar").exists()
assertThat(result).pom().exists()
assertThat(result).pom().matchesExpectedPom(kotlinStdlibJdk(kotlinVersion))
assertThat(result).module().exists()
assertThat(result).sourcesJar().exists()
assertThat(result).sourcesJar().containsAllSourceFiles()
assertThat(result).javadocJar().exists()
assertThat(result).javadocJar().containsFiles(ignoreAdditionalFiles = true, "index.html")
}

@TestParameterInjectorTest
fun dokka2Javadoc() {
val kotlinVersion = KotlinVersion.entries.last()
val original = kotlinJvmProjectSpec(kotlinVersion)
val project = original.copy(
plugins = original.plugins + dokka2JavadocPlugin,
basePluginConfig = original.basePluginConfig.replace("JavadocJar.Empty()", "JavadocJar.Dokka(\"dokkaGeneratePublicationJavadoc\")"),
)
val result = project.run(fixtures, testProjectDir, testOptions)

assertThat(result).outcome().succeeded()
assertThat(result).artifact("jar").exists()
assertThat(result).pom().exists()
assertThat(result).pom().matchesExpectedPom(kotlinStdlibJdk(kotlinVersion))
assertThat(result).module().exists()
assertThat(result).sourcesJar().exists()
assertThat(result).sourcesJar().containsAllSourceFiles()
assertThat(result).javadocJar().exists()
assertThat(result).javadocJar().containsFiles(ignoreAdditionalFiles = true, "index.html")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ fun ProjectSpec.run(fixtures: Path, temp: Path, options: TestOptions): ProjectRe
}

private fun supportsConfigCaching(plugins: List<PluginSpec>): Boolean {
// TODO https://github.com/Kotlin/dokka/issues/2231
return !plugins.any { it.id == dokkaPlugin.id }
// TODO can always return true when dropping support for dokka 1
return plugins.none { it.id == dokkaPlugin.id && it.version!!.startsWith("1.") }
}

private fun ProjectSpec.writeBuildFile(path: Path, repo: Path, options: TestOptions) {
Expand Down Expand Up @@ -187,6 +187,8 @@ private fun ProjectSpec.writeGradleProperties(path: Path, options: TestOptions)
appendLine("org.gradle.vfs.watch=false")
appendLine("kotlin.compiler.execution.strategy=in-process")
appendLine("kotlin.mpp.androidSourceSetLayoutVersion1.nowarn=true")
appendLine("org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled")
appendLine("org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true")
appendLine()

if (options.config == TestOptions.Config.PROPERTIES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ val kotlinAndroidPlugin = PluginSpec("org.jetbrains.kotlin.android")
val androidLibraryPlugin = PluginSpec("com.android.library")
val gradlePluginPublishPlugin = PluginSpec("com.gradle.plugin-publish")
val dokkaPlugin = PluginSpec("org.jetbrains.dokka", "1.8.10")
val dokka2Plugin = PluginSpec("org.jetbrains.dokka", "2.0.0-Beta")
val dokka2JavadocPlugin = PluginSpec("org.jetbrains.dokka-javadoc", "2.0.0-Beta")

val fixtures = Paths.get("src/integrationTest/fixtures2").absolute()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,16 @@ abstract class MavenPublishBaseExtension @Inject constructor(
private fun defaultJavaDocOption(javadocJar: Boolean, plainJavadocSupported: Boolean): JavadocJar {
return if (!javadocJar) {
JavadocJar.None()
} else if (project.plugins.hasPlugin("org.jetbrains.dokka") || project.plugins.hasPlugin("org.jetbrains.dokka-android")) {
} else if (project.plugins.hasPlugin("org.jetbrains.dokka-javadoc")) {
JavadocJar.Dokka("dokkaGeneratePublicationJavadoc")
} else if (project.plugins.hasPlugin("org.jetbrains.dokka")) {
val dokkaTask = project.provider {
val tasks = project.tasks.withType(DokkaTask::class.java)
tasks.singleOrNull()?.name ?: "dokkaHtml"
if (tasks.size == 0) {
"dokkaGeneratePublicationHtml"
} else {
tasks.singleOrNull()?.name ?: "dokkaHtml"
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With V2Enabled there will be 0 registered DokkaTask instances so we can use that as an indicator. When Dokka reached 2.1.0 we can make v2 mode required and simplify all of this to just JavadocJar.Dokka("dokkaGeneratePublicationHtml), like the javadoc block above.

}
JavadocJar.Dokka(dokkaTask)
} else if (plainJavadocSupported) {
Expand Down
Loading