1
+ import nl.jolanrensen.docProcessor.defaultProcessors.*
2
+ import nl.jolanrensen.docProcessor.gradle.creatingProcessDocTask
3
+ import org.gradle.jvm.tasks.Jar
4
+ import xyz.ronella.gradle.plugin.simple.git.task.GitTask
5
+
1
6
@Suppress(" DSL_SCOPE_VIOLATION" , " UnstableApiUsage" )
2
7
plugins {
3
8
kotlin(" jvm" )
@@ -10,6 +15,9 @@ plugins {
10
15
id(" org.jetbrains.kotlinx.kover" )
11
16
id(" org.jmailen.kotlinter" )
12
17
id(" org.jetbrains.kotlinx.dataframe" )
18
+ id(" nl.jolanrensen.docProcessor" )
19
+ id(" xyz.ronella.simple-git" )
20
+ idea
13
21
}
14
22
15
23
group = " org.jetbrains.kotlinx"
@@ -52,6 +60,66 @@ kotlin.sourceSets {
52
60
}
53
61
}
54
62
63
+ val generatedSourcesFolderName = " generated-sources"
64
+ val addGeneratedSourcesToGit by tasks.creating(GitTask ::class ) {
65
+ directory.set(file(" ." ))
66
+ command.set(" add" )
67
+ args.set(listOf (" -A" , generatedSourcesFolderName))
68
+ }
69
+
70
+ // Backup the kotlin source files location
71
+ val kotlinMainSources = kotlin.sourceSets.main.get().kotlin.sourceDirectories
72
+
73
+ // Task to generate the processed documentation
74
+ val processKDocsMain by creatingProcessDocTask(
75
+ sources = kotlinMainSources.filterNot { " build/generated" in it.path }, // Exclude generated sources
76
+ ) {
77
+ target = file(generatedSourcesFolderName)
78
+ processors = listOf (
79
+ INCLUDE_DOC_PROCESSOR ,
80
+ INCLUDE_FILE_DOC_PROCESSOR ,
81
+ INCLUDE_ARG_DOC_PROCESSOR ,
82
+ COMMENT_DOC_PROCESSOR ,
83
+ SAMPLE_DOC_PROCESSOR ,
84
+ )
85
+
86
+ task {
87
+ doLast {
88
+ // ensure generated sources are added to git
89
+ addGeneratedSourcesToGit.executeCommand()
90
+ }
91
+ }
92
+ }
93
+
94
+ // Exclude the generated/processed sources from the IDE
95
+ idea {
96
+ module {
97
+ excludeDirs.add(file(generatedSourcesFolderName))
98
+ }
99
+ }
100
+
101
+ // Modify all Jar tasks such that before running the Kotlin sources are set to
102
+ // the target of processKdocMain and they are returned back to normal afterwards.
103
+ tasks.withType<Jar > {
104
+ dependsOn(processKDocsMain)
105
+ outputs.upToDateWhen { false }
106
+
107
+ doFirst {
108
+ kotlin.sourceSets.main {
109
+ kotlin.setSrcDirs(
110
+ processKDocsMain.targets +
111
+ kotlinMainSources.filter { " build/generated" in it.path } // Include generated sources (which were excluded above)
112
+ )
113
+ }
114
+ }
115
+
116
+ doLast {
117
+ kotlin.sourceSets.main {
118
+ kotlin.setSrcDirs(kotlinMainSources)
119
+ }
120
+ }
121
+ }
122
+
55
123
korro {
56
124
docs = fileTree(rootProject.rootDir) {
57
125
include(" docs/StardustDocs/topics/*.md" )
@@ -169,3 +237,13 @@ dataframes {
169
237
name = " org.jetbrains.kotlinx.dataframe.samples.api.Repository"
170
238
}
171
239
}
240
+
241
+ // If we want to use Dokka, make sure to use the preprocessed sources
242
+ tasks.withType< org.jetbrains.dokka.gradle.AbstractDokkaLeafTask > {
243
+ dependsOn(processKDocsMain)
244
+ dokkaSourceSets {
245
+ all {
246
+ sourceRoot(processKDocsMain.target.get())
247
+ }
248
+ }
249
+ }
0 commit comments