@@ -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
@@ -257,25 +227,23 @@ idea {
257227 }
258228}
259229
260- // if `processKDocsMain` runs, the Jar tasks must run after it so the generated-sources are there
261- tasks.withType<Jar > {
262- mustRunAfter(tasks.generateKeywordsSrc, processKDocsMain)
263- }
264-
265230// If `changeJarTask` is run, modify all Jar tasks such that before running the Kotlin sources are set to
266231// the target of `processKdocMain`, and they are returned to normal afterward.
267232// This is usually only done when publishing
268233val changeJarTask by tasks.creating {
269234 outputs.upToDateWhen { false }
270235 doFirst {
271236 tasks.withType<Jar > {
272- dependsOn(processKDocsMain)
273237 doFirst {
274- require(processKDocsMainOutputs.toList().isNotEmpty()) {
275- logger.error(" `processKDocsMainOutputs` was empty, did `processKDocsMain` 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?" )
276244 }
277245 kotlin.sourceSets.main {
278- kotlin.setSrcDirs(processKDocsMainOutputs )
246+ kotlin.setSrcDirs(generatedSources.kotlin.srcDirs )
279247 }
280248 logger.lifecycle(" $this is run with modified sources: \" $generatedSourcesFolderName \" " )
281249 }
@@ -289,6 +257,11 @@ val changeJarTask by tasks.creating {
289257 }
290258}
291259
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+
292265// modify all publishing tasks to depend on `changeJarTask` so the sources are swapped out with generated sources
293266tasks.named { it.startsWith(" publish" ) }.configureEach {
294267 dependsOn(processKDocsMain, changeJarTask)
@@ -360,6 +333,11 @@ tasks.runKtlintFormatOverTestSourceSet {
360333 dependsOn(" kspTestKotlin" )
361334}
362335
336+ tasks.named(" runKtlintFormatOverGeneratedSourcesSourceSet" ) {
337+ dependsOn(tasks.generateKeywordsSrc)
338+ dependsOn(" kspKotlin" )
339+ }
340+
363341tasks.runKtlintCheckOverMainSourceSet {
364342 dependsOn(tasks.generateKeywordsSrc)
365343 dependsOn(" kspKotlin" )
@@ -370,6 +348,11 @@ tasks.runKtlintCheckOverTestSourceSet {
370348 dependsOn(" kspTestKotlin" )
371349}
372350
351+ tasks.named(" runKtlintCheckOverGeneratedSourcesSourceSet" ) {
352+ dependsOn(tasks.generateKeywordsSrc)
353+ dependsOn(" kspKotlin" )
354+ }
355+
373356kotlin {
374357 explicitApi()
375358}
0 commit comments