@@ -189,17 +189,34 @@ fun pathOf(vararg parts: String) = parts.joinToString(File.separator)
189189val processKDocsMainSources = (kotlinMainSources + kotlinTestSources)
190190 .filterNot { pathOf(" build" , " generated" ) in it.path }
191191
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+
192206// Task to generate the processed documentation
193207val processKDocsMain by creatingProcessDocTask(processKDocsMainSources) {
194208 target = file(generatedSourcesFolderName)
195209 arguments + = ARG_DOC_PROCESSOR_LOG_NOT_FOUND to false
210+
211+ // false, so `runKtlintFormatOverGeneratedSourcesSourceSet` can format the output
212+ outputReadOnly = false
213+
196214 exportAsHtml {
197215 dir = file(" ../docs/StardustDocs/snippets/kdocs" )
198216 }
199217 task {
200218 group = " KDocs"
201- // making sure it always runs, so targets is set
202- outputs.upToDateWhen { false }
219+ finalizedBy(" runKtlintFormatOverGeneratedSourcesSourceSet" )
203220 }
204221}
205222
@@ -210,37 +227,23 @@ idea {
210227 }
211228}
212229
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-
218230// If `changeJarTask` is run, modify all Jar tasks such that before running the Kotlin sources are set to
219231// the target of `processKdocMain`, and they are returned to normal afterward.
220232// This is usually only done when publishing
221233val changeJarTask by tasks.creating {
222234 outputs.upToDateWhen { false }
223235 doFirst {
224236 tasks.withType<Jar > {
225- dependsOn(processKDocsMain)
226237 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?" )
230244 }
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-
242245 kotlin.sourceSets.main {
243- kotlin.setSrcDirs(srcDirs)
246+ kotlin.setSrcDirs(generatedSources.kotlin. srcDirs)
244247 }
245248 logger.lifecycle(" $this is run with modified sources: \" $generatedSourcesFolderName \" " )
246249 }
@@ -254,6 +257,11 @@ val changeJarTask by tasks.creating {
254257 }
255258}
256259
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+
257265// modify all publishing tasks to depend on `changeJarTask` so the sources are swapped out with generated sources
258266tasks.named { it.startsWith(" publish" ) }.configureEach {
259267 dependsOn(processKDocsMain, changeJarTask)
@@ -325,6 +333,11 @@ tasks.runKtlintFormatOverTestSourceSet {
325333 dependsOn(" kspTestKotlin" )
326334}
327335
336+ tasks.named(" runKtlintFormatOverGeneratedSourcesSourceSet" ) {
337+ dependsOn(tasks.generateKeywordsSrc)
338+ dependsOn(" kspKotlin" )
339+ }
340+
328341tasks.runKtlintCheckOverMainSourceSet {
329342 dependsOn(tasks.generateKeywordsSrc)
330343 dependsOn(" kspKotlin" )
@@ -335,6 +348,11 @@ tasks.runKtlintCheckOverTestSourceSet {
335348 dependsOn(" kspTestKotlin" )
336349}
337350
351+ tasks.named(" runKtlintCheckOverGeneratedSourcesSourceSet" ) {
352+ dependsOn(tasks.generateKeywordsSrc)
353+ dependsOn(" kspKotlin" )
354+ }
355+
338356kotlin {
339357 explicitApi()
340358}
@@ -357,7 +375,7 @@ tasks.test {
357375 listOf (
358376 " org.jetbrains.kotlinx.dataframe.jupyter.*" ,
359377 " org.jetbrains.kotlinx.dataframe.jupyter.SampleNotebooksTests" ,
360- )
378+ ),
361379 )
362380 }
363381}
0 commit comments