Skip to content

Commit e095e33

Browse files
committed
prevent multiple warnings
1 parent c29ad27 commit e095e33

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

dokka-runners/dokka-gradle-plugin/src/main/kotlin/adapters/KotlinAdapter.kt

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import org.gradle.kotlin.dsl.*
1919
import org.jetbrains.dokka.gradle.DokkaBasePlugin
2020
import org.jetbrains.dokka.gradle.DokkaExtension
2121
import org.jetbrains.dokka.gradle.adapters.KotlinAdapter.Companion.currentKotlinToolingVersion
22-
import org.jetbrains.dokka.gradle.adapters.KotlinAdapter.Companion.findKotlinBasePlugins
2322
import org.jetbrains.dokka.gradle.adapters.KotlinAdapter.Companion.logKgpClassNotFoundWarning
2423
import org.jetbrains.dokka.gradle.engine.parameters.DokkaSourceSetSpec
2524
import org.jetbrains.dokka.gradle.engine.parameters.KotlinPlatform
@@ -41,8 +40,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataCompilation
4140
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
4241
import org.jetbrains.kotlin.tooling.core.KotlinToolingVersion
4342
import java.io.File
44-
import java.util.Collections.newSetFromMap
45-
import java.util.concurrent.ConcurrentHashMap
4643
import javax.inject.Inject
4744

4845
/**
@@ -261,40 +258,45 @@ abstract class KotlinAdapter @Inject constructor(
261258
"Dokka Gradle Plugin could not load KotlinBasePlugin in ${project.displayName}",
262259
kotlinBasePluginNotFoundException,
263260
)
261+
262+
/**
263+
* Keep track of which projects have been warned by [logKgpClassNotFoundWarning],
264+
* otherwise it'll log the same warning multiple times for the same project, which is annoying.
265+
*
266+
* The warning can be logged multiple times if a project has both
267+
* `org.jetbrains.dokka` and `org.jetbrains.dokka-javadoc` applied.
268+
*/
269+
fun checkIfAlreadyWarned(): Boolean {
270+
val key = "DOKKA INTERNAL - projectsWithKgpClassNotFoundWarningApplied"
271+
if (project.extra.has(key)) {
272+
return true
273+
} else {
274+
project.extra.set(key, true)
275+
return false
276+
}
277+
}
278+
264279
PluginId.kgpPlugins.forEach { pluginId ->
265280
project.pluginManager.withPlugin(pluginId) {
266-
if (!projectsWithKgpClassNotFoundWarningApplied.add(project.path)) {
267-
logger.warn(
268-
"""
269-
|warning: Dokka could not load KotlinBasePlugin in ${project.displayName}, even though plugin $pluginId is applied.
270-
|The most common cause is a Gradle limitation: the plugins applied to subprojects should be consistent.
271-
|Please try the following:
272-
|1. Apply the Dokka and Kotlin plugins to the root project using the `plugins {}` DSL.
273-
| (If the root project does not need the plugins, use 'apply false')
274-
|2. Remove the Dokka and Kotlin plugins versions in the subprojects.
275-
|For more information see:
276-
| - https://docs.gradle.org/current/userguide/plugins_intermediate.html#sec:plugins_apply
277-
| - https://github.com/gradle/gradle/issues/25616
278-
| - https://github.com/gradle/gradle/issues/35117
279-
|Please report any feedback or problems https://kotl.in/dokka-issues
280-
|""".trimMargin()
281-
)
282-
} else {
283-
logger.lifecycle("project ${project.path} already applied Dokka Gradle Plugin's KotlinBasePlugin warning, skipping")
284-
}
281+
if (checkIfAlreadyWarned()) return@withPlugin
282+
logger.warn(
283+
"""
284+
|warning: Dokka could not load KotlinBasePlugin in ${project.displayName}, even though plugin $pluginId is applied.
285+
|The most common cause is a Gradle limitation: the plugins applied to subprojects should be consistent.
286+
|Please try the following:
287+
|1. Apply the Dokka and Kotlin plugins to the root project using the `plugins {}` DSL.
288+
| (If the root project does not need the plugins, use 'apply false')
289+
|2. Remove the Dokka and Kotlin plugins versions in the subprojects.
290+
|For more information see:
291+
| - https://docs.gradle.org/current/userguide/plugins_intermediate.html#sec:plugins_apply
292+
| - https://github.com/gradle/gradle/issues/25616
293+
| - https://github.com/gradle/gradle/issues/35117
294+
|Please report any feedback or problems https://kotl.in/dokka-issues
295+
|""".trimMargin()
296+
)
285297
}
286298
}
287299
}
288-
289-
/**
290-
* Keep track of which projects have been warned by [logKgpClassNotFoundWarning],
291-
* otherwise it'll log the same warning multiple times for the same project, which is annoying.
292-
*
293-
* [logKgpClassNotFoundWarning] will be triggered multiple times because
294-
* [findKotlinBasePlugins] reacts to all [KotlinBasePlugin].
295-
* A project could have multiple plugins that implement this class.
296-
*/
297-
private val projectsWithKgpClassNotFoundWarningApplied: MutableSet<String> = newSetFromMap(ConcurrentHashMap())
298300
}
299301
}
300302

0 commit comments

Comments
 (0)