@@ -6,34 +6,49 @@ import org.jetbrains.dokka.gradle.isAndroidTarget
6
6
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
7
7
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation
8
8
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
9
+ import org.jetbrains.kotlin.gradle.tasks.KotlinCompileTool
9
10
10
11
internal fun Project.classpathOf (sourceSet : KotlinSourceSet ): FileCollection {
11
12
val compilations = compilationsOf(sourceSet)
12
13
return if (compilations.isNotEmpty()) {
13
14
compilations
14
15
.map { compilation -> compilation.compileClasspathOf(project = this ) }
15
- .reduce { acc, fileCollection -> acc + fileCollection }
16
+ .reduce( FileCollection ::plus)
16
17
} else {
17
18
// Dokka suppresses source sets that do no have compilations
18
19
// since such configuration is invalid, it reports a warning or an error
19
20
sourceSet.withAllDependentSourceSets()
20
- .toList()
21
21
.map { it.kotlin.sourceDirectories }
22
- .reduce { acc, fileCollection -> acc + fileCollection }
22
+ .reduce( FileCollection ::plus)
23
23
}
24
24
}
25
25
26
26
private fun KotlinCompilation.compileClasspathOf (project : Project ): FileCollection {
27
+ val kgpVersion = project.getKgpVersion()
28
+
29
+ // if KGP version < 1.9 or org.jetbrains.dokka.classpath.useOldResolution=true
30
+ // we will use old (pre 1.9) resolution of classpath
31
+ if (kgpVersion == null ||
32
+ kgpVersion < KotlinGradlePluginVersion (1 , 9 , 0 ) ||
33
+ project.classpathProperty(" useOldResolution" , default = false )
34
+ ) {
35
+ return oldCompileClasspathOf(project)
36
+ }
37
+
38
+ return newCompileClasspathOf(project)
39
+ }
40
+
41
+ private fun KotlinCompilation.newCompileClasspathOf (project : Project ): FileCollection {
42
+ val compilationClasspath = (compileTaskProvider.get() as ? KotlinCompileTool )?.libraries ? : project.files()
43
+ return compilationClasspath + platformDependencyFiles(project)
44
+ }
45
+
46
+ private fun KotlinCompilation.oldCompileClasspathOf (project : Project ): FileCollection {
27
47
if (this .target.isAndroidTarget()) { // Workaround for https://youtrack.jetbrains.com/issue/KT-33893
28
48
return this .classpathOf(project)
29
49
}
30
50
31
- val platformDependencyFiles: FileCollection = (this as ? AbstractKotlinNativeCompilation )
32
- ?.target?.project?.configurations
33
- ?.findByName(@Suppress(" DEPRECATION" ) this .defaultSourceSet.implementationMetadataConfigurationName) // KT-58640
34
- ? : project.files()
35
-
36
- return this .compileDependencyFiles + platformDependencyFiles + this .classpathOf(project)
51
+ return this .compileDependencyFiles + platformDependencyFiles(project) + this .classpathOf(project)
37
52
}
38
53
39
54
private fun KotlinCompilation.classpathOf (project : Project ): FileCollection {
@@ -43,7 +58,7 @@ private fun KotlinCompilation.classpathOf(project: Project): FileCollection {
43
58
val shouldKeepBackwardsCompatibility = (kgpVersion != null && kgpVersion < KotlinGradlePluginVersion (1 , 7 , 0 ))
44
59
return if (shouldKeepBackwardsCompatibility) {
45
60
// removed since 1.9.0, left for compatibility with < Kotlin 1.7
46
- val classpathGetter= kotlinCompile::class .members
61
+ val classpathGetter = kotlinCompile::class .members
47
62
.first { it.name == " getClasspath" }
48
63
classpathGetter.call(kotlinCompile) as FileCollection
49
64
} else {
@@ -60,3 +75,16 @@ private fun KotlinCompilation.getKotlinCompileTask(kgpVersion: KotlinGradlePlugi
60
75
this .compileTaskProvider.get() as ? KotlinCompile // introduced in 1.8.0
61
76
}
62
77
}
78
+
79
+ private fun KotlinCompilation.platformDependencyFiles (project : Project ): FileCollection {
80
+ val excludePlatformDependencyFiles = project.classpathProperty(" excludePlatformDependencyFiles" , default = false )
81
+
82
+ if (excludePlatformDependencyFiles) return project.files()
83
+ return (this as ? AbstractKotlinNativeCompilation )
84
+ ?.target?.project?.configurations
85
+ ?.findByName(@Suppress(" DEPRECATION" ) this .defaultSourceSet.implementationMetadataConfigurationName) // KT-58640
86
+ ? : project.files()
87
+ }
88
+
89
+ private fun Project.classpathProperty (name : String , default : Boolean ): Boolean =
90
+ (findProperty(" org.jetbrains.dokka.classpath.$name " ) as ? String )?.toBoolean() ? : default
0 commit comments