@@ -171,30 +171,6 @@ tasks.withType<KorroTask> {
171
171
172
172
// region docPreprocessor
173
173
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
-
198
174
val generatedSourcesFolderName = " generated-sources"
199
175
200
176
// Backup the kotlin source files location
@@ -213,40 +189,34 @@ fun pathOf(vararg parts: String) = parts.joinToString(File.separator)
213
189
val processKDocsMainSources = (kotlinMainSources + kotlinTestSources)
214
190
.filterNot { pathOf(" build" , " generated" ) in it.path }
215
191
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
+ )
232
203
}
204
+ }
233
205
234
206
// Task to generate the processed documentation
235
207
val processKDocsMain by creatingProcessDocTask(processKDocsMainSources) {
236
208
target = file(generatedSourcesFolderName)
237
209
arguments + = ARG_DOC_PROCESSOR_LOG_NOT_FOUND to false
238
210
239
- // false, so ktlintFormatGeneratedSources can format the output
211
+ // false, so `runKtlintFormatOverGeneratedSourcesSourceSet` can format the output
240
212
outputReadOnly = false
241
213
242
214
exportAsHtml {
243
215
dir = file(" ../docs/StardustDocs/snippets/kdocs" )
244
216
}
245
217
task {
246
218
group = " KDocs"
247
- // making sure it always runs, so targets is set
248
- outputs.upToDateWhen { false }
249
- finalizedBy(ktlintFormatGeneratedSources)
219
+ finalizedBy(" runKtlintFormatOverGeneratedSourcesSourceSet" )
250
220
}
251
221
}
252
222
@@ -257,25 +227,23 @@ idea {
257
227
}
258
228
}
259
229
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
-
265
230
// If `changeJarTask` is run, modify all Jar tasks such that before running the Kotlin sources are set to
266
231
// the target of `processKdocMain`, and they are returned to normal afterward.
267
232
// This is usually only done when publishing
268
233
val changeJarTask by tasks.creating {
269
234
outputs.upToDateWhen { false }
270
235
doFirst {
271
236
tasks.withType<Jar > {
272
- dependsOn(processKDocsMain)
273
237
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?" )
276
244
}
277
245
kotlin.sourceSets.main {
278
- kotlin.setSrcDirs(processKDocsMainOutputs )
246
+ kotlin.setSrcDirs(generatedSources.kotlin.srcDirs )
279
247
}
280
248
logger.lifecycle(" $this is run with modified sources: \" $generatedSourcesFolderName \" " )
281
249
}
@@ -289,6 +257,11 @@ val changeJarTask by tasks.creating {
289
257
}
290
258
}
291
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
+
292
265
// modify all publishing tasks to depend on `changeJarTask` so the sources are swapped out with generated sources
293
266
tasks.named { it.startsWith(" publish" ) }.configureEach {
294
267
dependsOn(processKDocsMain, changeJarTask)
@@ -360,6 +333,11 @@ tasks.runKtlintFormatOverTestSourceSet {
360
333
dependsOn(" kspTestKotlin" )
361
334
}
362
335
336
+ tasks.named(" runKtlintFormatOverGeneratedSourcesSourceSet" ) {
337
+ dependsOn(tasks.generateKeywordsSrc)
338
+ dependsOn(" kspKotlin" )
339
+ }
340
+
363
341
tasks.runKtlintCheckOverMainSourceSet {
364
342
dependsOn(tasks.generateKeywordsSrc)
365
343
dependsOn(" kspKotlin" )
@@ -370,6 +348,11 @@ tasks.runKtlintCheckOverTestSourceSet {
370
348
dependsOn(" kspTestKotlin" )
371
349
}
372
350
351
+ tasks.named(" runKtlintCheckOverGeneratedSourcesSourceSet" ) {
352
+ dependsOn(tasks.generateKeywordsSrc)
353
+ dependsOn(" kspKotlin" )
354
+ }
355
+
373
356
kotlin {
374
357
explicitApi()
375
358
}
0 commit comments