@@ -171,30 +171,6 @@ tasks.withType<KorroTask> {
171171
172172// region docPreprocessor
173173
174- val ktlintCheckGeneratedSources by tasks.creating {
175- doFirst {
176- tasks.runKtlintCheckOverMainSourceSet.configure {
177- source(generatedSourcesFolderName)
178- }
179- }
180- finalizedBy(tasks.ktlintCheck)
181- }
182-
183- tasks.runKtlintFormatOverMainSourceSet {
184- doFirst {
185- println (" running runKtlintFormatOverMainSourceSet on ${source.files} " )
186- }
187- }
188-
189- val ktlintFormatGeneratedSources by tasks.creating {
190- doFirst {
191- tasks.runKtlintFormatOverMainSourceSet.configure {
192- source(generatedSourcesFolderName)
193- }
194- }
195- finalizedBy(tasks.ktlintFormat)
196- }
197-
198174val generatedSourcesFolderName = " generated-sources"
199175
200176// Backup the kotlin source files location
@@ -213,40 +189,34 @@ fun pathOf(vararg parts: String) = parts.joinToString(File.separator)
213189val processKDocsMainSources = (kotlinMainSources + kotlinTestSources)
214190 .filterNot { pathOf(" build" , " generated" ) in it.path }
215191
216- // Raw processKDocsMain output; includes both generated main and -test sources
217- // Should be the same as processKDocsMain.targets after running it
218- val processKDocsMainRawOutputs
219- get() = processKDocsMainSources.map {
220- projectDir
221- .resolve(generatedSourcesFolderName)
222- .resolve(it.relativeTo(projectDir))
223- }
224-
225- // processKDocsMain output files; can be used as source set to generate sources.jar (after running processKDocsMain).
226- val processKDocsMainOutputs
227- get() = processKDocsMainRawOutputs.filterNot {
228- pathOf(" src" , " test" , " kotlin" ) in it.path || pathOf(" src" , " test" , " java" ) in it.path
229- } + kotlinMainSources.filter {
230- // Include generated sources (which were excluded above)
231- pathOf(" build" , " generated" ) in it.path
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+ )
232203 }
204+ }
233205
234206// Task to generate the processed documentation
235207val processKDocsMain by creatingProcessDocTask(processKDocsMainSources) {
236208 target = file(generatedSourcesFolderName)
237209 arguments + = ARG_DOC_PROCESSOR_LOG_NOT_FOUND to false
238210
239- // false, so ktlintFormatGeneratedSources can format the output
211+ // false, so `runKtlintFormatOverGeneratedSourcesSourceSet` can format the output
240212 outputReadOnly = false
241213
242214 exportAsHtml {
243215 dir = file(" ../docs/StardustDocs/snippets/kdocs" )
244216 }
245217 task {
246218 group = " KDocs"
247- // making sure it always runs, so targets is set
248- outputs.upToDateWhen { false }
249- finalizedBy(ktlintFormatGeneratedSources)
219+ finalizedBy(" runKtlintFormatOverGeneratedSourcesSourceSet" )
250220 }
251221}
252222
@@ -271,11 +241,15 @@ val changeJarTask by tasks.creating {
271241 tasks.withType<Jar > {
272242 dependsOn(processKDocsMain)
273243 doFirst {
274- require(processKDocsMainOutputs.toList().isNotEmpty()) {
275- logger.error(" `processKDocsMainOutputs` was empty, did `processKDocsMain` run before this task?" )
244+ require(
245+ generatedSources.kotlin.srcDirs
246+ .toList()
247+ .isNotEmpty(),
248+ ) {
249+ logger.error(" `processKDocsMain`'s outputs are empty, did `processKDocsMain` run before this task?" )
276250 }
277251 kotlin.sourceSets.main {
278- kotlin.setSrcDirs(processKDocsMainOutputs )
252+ kotlin.setSrcDirs(generatedSources.kotlin.srcDirs )
279253 }
280254 logger.lifecycle(" $this is run with modified sources: \" $generatedSourcesFolderName \" " )
281255 }
@@ -360,6 +334,11 @@ tasks.runKtlintFormatOverTestSourceSet {
360334 dependsOn(" kspTestKotlin" )
361335}
362336
337+ tasks.named(" runKtlintFormatOverGeneratedSourcesSourceSet" ) {
338+ dependsOn(tasks.generateKeywordsSrc)
339+ dependsOn(" kspKotlin" )
340+ }
341+
363342tasks.runKtlintCheckOverMainSourceSet {
364343 dependsOn(tasks.generateKeywordsSrc)
365344 dependsOn(" kspKotlin" )
@@ -370,6 +349,11 @@ tasks.runKtlintCheckOverTestSourceSet {
370349 dependsOn(" kspTestKotlin" )
371350}
372351
352+ tasks.named(" runKtlintCheckOverGeneratedSourcesSourceSet" ) {
353+ dependsOn(tasks.generateKeywordsSrc)
354+ dependsOn(" kspKotlin" )
355+ }
356+
373357kotlin {
374358 explicitApi()
375359}
0 commit comments