1
1
import nl.jolanrensen.docProcessor.defaultProcessors.*
2
2
import nl.jolanrensen.docProcessor.gradle.creatingProcessDocTask
3
3
import org.gradle.jvm.tasks.Jar
4
+ import xyz.ronella.gradle.plugin.simple.git.task.GitTask
4
5
5
6
@Suppress(" DSL_SCOPE_VIOLATION" , " UnstableApiUsage" )
6
7
plugins {
@@ -14,8 +15,9 @@ plugins {
14
15
id(" org.jetbrains.kotlinx.kover" )
15
16
id(" org.jmailen.kotlinter" )
16
17
id(" org.jetbrains.kotlinx.dataframe" )
17
- // id("com.github.jolanrensen.docProcessorGradlePlugin") version "v0.1.0"
18
- id(" nl.jolanrensen.docProcessor" ) version " 0.1.1"
18
+ id(" nl.jolanrensen.docProcessor" )
19
+ id(" xyz.ronella.simple-git" )
20
+ idea
19
21
}
20
22
21
23
group = " org.jetbrains.kotlinx"
@@ -58,58 +60,62 @@ kotlin.sourceSets {
58
60
}
59
61
}
60
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
+
61
70
// Backup the kotlin source files location
62
71
val kotlinMainSources = kotlin.sourceSets.main.get().kotlin.sourceDirectories
63
72
73
+ // Task to generate the processed documentation
64
74
val processKDocsMain by creatingProcessDocTask(
65
- sources = kotlinMainSources.filterNot { " build/generated" in it.path } // Exclude generated sources
75
+ sources = kotlinMainSources.filterNot { " build/generated" in it.path }, // Exclude generated sources
66
76
) {
67
- target = file(" generated-sources " )
77
+ target = file(generatedSourcesFolderName )
68
78
processors = listOf (
69
79
INCLUDE_DOC_PROCESSOR ,
70
80
INCLUDE_FILE_DOC_PROCESSOR ,
71
81
INCLUDE_ARG_DOC_PROCESSOR ,
72
82
COMMENT_DOC_PROCESSOR ,
73
83
SAMPLE_DOC_PROCESSOR ,
74
84
)
75
- }
76
85
77
- // As a bonus, this will update dokka if you use that
78
- tasks.withType< org.jetbrains.dokka.gradle.AbstractDokkaLeafTask > {
79
- dependsOn(processKDocsMain)
80
- dokkaSourceSets {
81
- all {
82
- sourceRoot(processKDocsMain.target.get())
86
+ task {
87
+ doLast {
88
+ // ensure generated sources are added to git
89
+ addGeneratedSourcesToGit.executeCommand()
83
90
}
84
91
}
85
92
}
86
93
94
+ // Exclude the generated/processed sources from the IDE
95
+ idea {
96
+ module {
97
+ excludeDirs.add(file(generatedSourcesFolderName))
98
+ }
99
+ }
100
+
87
101
// Modify all Jar tasks such that before running the Kotlin sources are set to
88
- // the target of processKdocIncludeMain and they are returned back to normal afterwards.
102
+ // the target of processKdocMain and they are returned back to normal afterwards.
89
103
tasks.withType<Jar > {
90
104
dependsOn(processKDocsMain)
91
105
outputs.upToDateWhen { false }
92
106
93
107
doFirst {
94
- kotlin {
95
- sourceSets {
96
- main {
97
- kotlin.setSrcDirs(
98
- processKDocsMain.targets +
99
- kotlinMainSources.filter { " build/generated" in it.path } // Include generated sources (which were excluded above)
100
- )
101
- }
102
- }
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
+ )
103
113
}
104
114
}
105
115
106
116
doLast {
107
- kotlin {
108
- sourceSets {
109
- main {
110
- kotlin.setSrcDirs(kotlinMainSources)
111
- }
112
- }
117
+ kotlin.sourceSets.main {
118
+ kotlin.setSrcDirs(kotlinMainSources)
113
119
}
114
120
}
115
121
}
@@ -231,3 +237,13 @@ dataframes {
231
237
name = " org.jetbrains.kotlinx.dataframe.samples.api.Repository"
232
238
}
233
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