Skip to content

Commit e8423ec

Browse files
authored
Deprecate methods for adding/removing task dependencies (#2857)
1 parent 00210fd commit e8423ec

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTask.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import org.gradle.api.tasks.Internal
66
import org.gradle.api.tasks.Nested
77
import org.gradle.work.DisableCachingByDefault
88

9+
private const val DEPRECATION_MESSAGE = """
10+
It is an anti-pattern to declare cross-project dependencies as it leads to various build problems.
11+
For this reason, this API wil be removed with the introduction of project isolation.
12+
When it happens, we will provide a migration guide. In the meantime, you can keep using this API
13+
if you have to, but please don't rely on it if possible. If you don't want to document a certain project,
14+
don't apply the Dokka plugin for it, or disable individual project tasks using the Gradle API .
15+
"""
16+
17+
@Suppress("DEPRECATION")
918
@DisableCachingByDefault(because = "Abstract super-class, not to be instantiated directly")
1019
abstract class AbstractDokkaParentTask : AbstractDokkaTask() {
1120

@@ -21,50 +30,60 @@ abstract class AbstractDokkaParentTask : AbstractDokkaTask() {
2130
.toSet()
2231

2332
/* By task reference */
33+
@Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING)
2434
fun addChildTask(task: AbstractDokkaTask) {
2535
childDokkaTaskPaths = childDokkaTaskPaths + task.path
2636
}
2737

38+
@Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING)
2839
fun removeChildTask(task: AbstractDokkaTask) {
2940
childDokkaTaskPaths = childDokkaTaskPaths - task.path
3041
}
3142

3243
/* By path */
44+
@Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING)
3345
fun addChildTask(path: String) {
3446
childDokkaTaskPaths = childDokkaTaskPaths + project.absoluteProjectPath(path)
3547
}
3648

49+
@Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING)
3750
fun removeChildTask(path: String) {
3851
childDokkaTaskPaths = childDokkaTaskPaths - project.absoluteProjectPath(path)
3952
}
4053

4154
/* By project reference and name */
55+
@Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING)
4256
fun addChildTasks(projects: Iterable<Project>, childTasksName: String) {
4357
projects.forEach { project ->
4458
addChildTask(project.absoluteProjectPath(childTasksName))
4559
}
4660
}
4761

62+
@Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING)
4863
fun removeChildTasks(projects: Iterable<Project>, childTasksName: String) {
4964
projects.forEach { project ->
5065
removeChildTask(project.absoluteProjectPath(childTasksName))
5166
}
5267
}
5368

69+
@Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING)
5470
fun addSubprojectChildTasks(childTasksName: String) {
5571
addChildTasks(project.subprojects, childTasksName)
5672
}
5773

74+
@Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING)
5875
fun removeSubprojectChildTasks(childTasksName: String) {
5976
removeChildTasks(project.subprojects, childTasksName)
6077
}
6178

79+
@Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING)
6280
fun removeChildTasks(project: Project) {
6381
childDokkaTaskPaths = childDokkaTaskPaths.filter { path ->
6482
parsePath(path).parent != parsePath(project.path)
6583
}.toSet()
6684
}
6785

86+
@Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING)
6887
fun removeChildTasks(projects: Iterable<Project>) {
6988
projects.forEach { project -> removeChildTasks(project) }
7089
}

runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ abstract class DokkaMultiModuleTask : AbstractDokkaParentTask() {
6767
task.path to task.dokkaSourceSets.flatMap { it.includes }.toSet()
6868
}
6969

70+
// The method contains a reference to internal Gradle API that is nice not to use.
71+
// There was an attempt to get rid of it, but it was not successful
72+
// See: https://github.com/Kotlin/dokka/pull/2835
7073
@Internal
7174
override fun getTaskDependencies(): TaskDependencyInternal =
7275
super.getTaskDependencies() + childDokkaTasks

runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaPlugin.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import org.gradle.api.DefaultTask
44
import org.gradle.api.Plugin
55
import org.gradle.api.Project
66
import org.gradle.api.artifacts.Dependency
7-
import org.gradle.api.plugins.JavaBasePlugin
87
import org.gradle.kotlin.dsl.register
98
import org.gradle.util.GradleVersion
109

@@ -69,6 +68,7 @@ open class DokkaPlugin : Plugin<Project> {
6968
project.maybeCreateDokkaRuntimeConfiguration(multiModuleName)
7069

7170
project.tasks.register<DokkaMultiModuleTask>(multiModuleName) {
71+
@Suppress("DEPRECATION")
7272
addSubprojectChildTasks("${name}Partial")
7373
configuration()
7474
description = "Runs all subprojects '$name' tasks and generates module navigation page"
@@ -85,6 +85,7 @@ open class DokkaPlugin : Plugin<Project> {
8585
}
8686

8787
project.tasks.register<DokkaCollectorTask>("${name}Collector") {
88+
@Suppress("DEPRECATION")
8889
addSubprojectChildTasks(name)
8990
description =
9091
"Generates documentation merging all subprojects '$name' tasks into one virtual module"

runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTaskTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
@file:Suppress("DEPRECATION")
2+
13
package org.jetbrains.dokka.gradle
24

35
import org.gradle.api.Project
4-
import org.gradle.api.UnknownTaskException
56
import org.gradle.kotlin.dsl.create
67
import org.gradle.kotlin.dsl.getByName
78
import org.gradle.testfixtures.ProjectBuilder

runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTaskTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
@file:Suppress("UnstableApiUsage")
1+
@file:Suppress("UnstableApiUsage", "DEPRECATION")
22

33
package org.jetbrains.dokka.gradle
44

5-
import org.gradle.kotlin.dsl.*
5+
import org.gradle.kotlin.dsl.create
6+
import org.gradle.kotlin.dsl.withType
67
import org.gradle.testfixtures.ProjectBuilder
78
import org.jetbrains.dokka.*
89
import java.io.File

0 commit comments

Comments
 (0)