@@ -189,17 +189,34 @@ fun pathOf(vararg parts: String) = parts.joinToString(File.separator)
189
189
val processKDocsMainSources = (kotlinMainSources + kotlinTestSources)
190
190
.filterNot { pathOf(" build" , " generated" ) in it.path }
191
191
192
+ // sourceset of the generated sources as a result of `processKDocsMain`, this will create linter tasks
193
+ val generatedSources by kotlin.sourceSets.creating {
194
+ kotlin {
195
+ setSrcDirs(
196
+ listOf (
197
+ " build/generated/ksp/main/kotlin/" ,
198
+ " core/build/generatedSrc" ,
199
+ " $generatedSourcesFolderName /src/main/kotlin" ,
200
+ " $generatedSourcesFolderName /src/main/java" ,
201
+ ),
202
+ )
203
+ }
204
+ }
205
+
192
206
// Task to generate the processed documentation
193
207
val processKDocsMain by creatingProcessDocTask(processKDocsMainSources) {
194
208
target = file(generatedSourcesFolderName)
195
209
arguments + = ARG_DOC_PROCESSOR_LOG_NOT_FOUND to false
210
+
211
+ // false, so `runKtlintFormatOverGeneratedSourcesSourceSet` can format the output
212
+ outputReadOnly = false
213
+
196
214
exportAsHtml {
197
215
dir = file(" ../docs/StardustDocs/snippets/kdocs" )
198
216
}
199
217
task {
200
218
group = " KDocs"
201
- // making sure it always runs, so targets is set
202
- outputs.upToDateWhen { false }
219
+ finalizedBy(" runKtlintFormatOverGeneratedSourcesSourceSet" )
203
220
}
204
221
}
205
222
@@ -210,37 +227,23 @@ idea {
210
227
}
211
228
}
212
229
213
- // if `processKDocsMain` runs, the Jar tasks must run after it so the generated-sources are there
214
- tasks.withType<Jar > {
215
- mustRunAfter(tasks.generateKeywordsSrc, processKDocsMain)
216
- }
217
-
218
230
// If `changeJarTask` is run, modify all Jar tasks such that before running the Kotlin sources are set to
219
231
// the target of `processKdocMain`, and they are returned to normal afterward.
220
232
// This is usually only done when publishing
221
233
val changeJarTask by tasks.creating {
222
234
outputs.upToDateWhen { false }
223
235
doFirst {
224
236
tasks.withType<Jar > {
225
- dependsOn(processKDocsMain)
226
237
doFirst {
227
- val targets = processKDocsMain.targets
228
- require(targets.toList().isNotEmpty()) {
229
- logger.error(" `processKDocsMain.targets` was empty, did it run before this task?" )
238
+ require(
239
+ generatedSources.kotlin.srcDirs
240
+ .toList()
241
+ .isNotEmpty(),
242
+ ) {
243
+ logger.error(" `processKDocsMain`'s outputs are empty, did `processKDocsMain` run before this task?" )
230
244
}
231
- val srcDirs = targets
232
- .filterNot {
233
- pathOf(" src" , " test" , " kotlin" ) in it.path ||
234
- pathOf(" src" , " test" , " java" ) in it.path
235
- } // filter out test sources again
236
- .plus(
237
- kotlinMainSources.filter {
238
- pathOf(" build" , " generated" ) in it.path
239
- },
240
- ) // Include generated sources (which were excluded above)
241
-
242
245
kotlin.sourceSets.main {
243
- kotlin.setSrcDirs(srcDirs)
246
+ kotlin.setSrcDirs(generatedSources.kotlin. srcDirs)
244
247
}
245
248
logger.lifecycle(" $this is run with modified sources: \" $generatedSourcesFolderName \" " )
246
249
}
@@ -254,6 +257,11 @@ val changeJarTask by tasks.creating {
254
257
}
255
258
}
256
259
260
+ // if `processKDocsMain` runs, the Jar tasks must run after it so the generated-sources are there
261
+ tasks.withType<Jar > {
262
+ mustRunAfter(changeJarTask, tasks.generateKeywordsSrc, processKDocsMain)
263
+ }
264
+
257
265
// modify all publishing tasks to depend on `changeJarTask` so the sources are swapped out with generated sources
258
266
tasks.named { it.startsWith(" publish" ) }.configureEach {
259
267
dependsOn(processKDocsMain, changeJarTask)
@@ -325,6 +333,11 @@ tasks.runKtlintFormatOverTestSourceSet {
325
333
dependsOn(" kspTestKotlin" )
326
334
}
327
335
336
+ tasks.named(" runKtlintFormatOverGeneratedSourcesSourceSet" ) {
337
+ dependsOn(tasks.generateKeywordsSrc)
338
+ dependsOn(" kspKotlin" )
339
+ }
340
+
328
341
tasks.runKtlintCheckOverMainSourceSet {
329
342
dependsOn(tasks.generateKeywordsSrc)
330
343
dependsOn(" kspKotlin" )
@@ -335,6 +348,11 @@ tasks.runKtlintCheckOverTestSourceSet {
335
348
dependsOn(" kspTestKotlin" )
336
349
}
337
350
351
+ tasks.named(" runKtlintCheckOverGeneratedSourcesSourceSet" ) {
352
+ dependsOn(tasks.generateKeywordsSrc)
353
+ dependsOn(" kspKotlin" )
354
+ }
355
+
338
356
kotlin {
339
357
explicitApi()
340
358
}
@@ -357,7 +375,7 @@ tasks.test {
357
375
listOf (
358
376
" org.jetbrains.kotlinx.dataframe.jupyter.*" ,
359
377
" org.jetbrains.kotlinx.dataframe.jupyter.SampleNotebooksTests" ,
360
- )
378
+ ),
361
379
)
362
380
}
363
381
}
0 commit comments