Skip to content

Commit a4fecde

Browse files
committed
enabled docProcessor plugin and configured auto git-add with simple-git
1 parent a32deb8 commit a4fecde

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ plugins {
1414
id("org.jetbrains.dokka") version libs.versions.dokka
1515
id("org.jetbrains.kotlinx.kover") version libs.versions.kover
1616
id("org.jmailen.kotlinter") version libs.versions.ktlint
17+
id("nl.jolanrensen.docProcessor") version libs.versions.docProcessor apply false
18+
id("xyz.ronella.simple-git") version libs.versions.simpleGit apply false
1719
}
1820

1921
val jupyterApiTCRepo: String by project

core/build.gradle.kts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
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+
16
@Suppress("DSL_SCOPE_VIOLATION", "UnstableApiUsage")
27
plugins {
38
kotlin("jvm")
@@ -10,6 +15,9 @@ plugins {
1015
id("org.jetbrains.kotlinx.kover")
1116
id("org.jmailen.kotlinter")
1217
id("org.jetbrains.kotlinx.dataframe")
18+
id("nl.jolanrensen.docProcessor")
19+
id("xyz.ronella.simple-git")
20+
idea
1321
}
1422

1523
group = "org.jetbrains.kotlinx"
@@ -52,6 +60,66 @@ kotlin.sourceSets {
5260
}
5361
}
5462

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+
55123
korro {
56124
docs = fileTree(rootProject.rootDir) {
57125
include("docs/StardustDocs/topics/*.md")
@@ -169,3 +237,13 @@ dataframes {
169237
name = "org.jetbrains.kotlinx.dataframe.samples.api.Repository"
170238
}
171239
}
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+
}

gradle/libs.versions.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ junit = "4.13.2"
2424
kotestAsserions = "4.6.3"
2525
jsoup = "1.14.3"
2626
arrow = "10.0.0"
27+
docProcessor = "0.1.0"
28+
simpleGit = "2.0.1"
2729

2830
[libraries]
2931
ksp-gradle = { group = "com.google.devtools.ksp", name = "symbol-processing-gradle-plugin", version.ref = "ksp" }
@@ -65,3 +67,5 @@ korro = { id = "io.github.devcrocod.korro", version.ref = "korro" }
6567
kotlinter = { id = "org.jmailen.kotlinter", version.ref = "ktlint" }
6668
dataframe = { id = "org.jetbrains.kotlinx.dataframe", version.ref = "dataframe" }
6769
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
70+
docProcessor = { id = "nl.jolanrensen.docProcessor", version.ref = "docProcessor" }
71+
simpleGit = { id = "xyz.ronella.simple-git", version.ref = "simpleGit"}

0 commit comments

Comments
 (0)