@@ -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
@@ -271,11 +241,15 @@ val changeJarTask by tasks.creating {
271
241
tasks.withType<Jar > {
272
242
dependsOn(processKDocsMain)
273
243
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?" )
276
250
}
277
251
kotlin.sourceSets.main {
278
- kotlin.setSrcDirs(processKDocsMainOutputs )
252
+ kotlin.setSrcDirs(generatedSources.kotlin.srcDirs )
279
253
}
280
254
logger.lifecycle(" $this is run with modified sources: \" $generatedSourcesFolderName \" " )
281
255
}
@@ -360,6 +334,11 @@ tasks.runKtlintFormatOverTestSourceSet {
360
334
dependsOn(" kspTestKotlin" )
361
335
}
362
336
337
+ tasks.named(" runKtlintFormatOverGeneratedSourcesSourceSet" ) {
338
+ dependsOn(tasks.generateKeywordsSrc)
339
+ dependsOn(" kspKotlin" )
340
+ }
341
+
363
342
tasks.runKtlintCheckOverMainSourceSet {
364
343
dependsOn(tasks.generateKeywordsSrc)
365
344
dependsOn(" kspKotlin" )
@@ -370,6 +349,11 @@ tasks.runKtlintCheckOverTestSourceSet {
370
349
dependsOn(" kspTestKotlin" )
371
350
}
372
351
352
+ tasks.named(" runKtlintCheckOverGeneratedSourcesSourceSet" ) {
353
+ dependsOn(tasks.generateKeywordsSrc)
354
+ dependsOn(" kspKotlin" )
355
+ }
356
+
373
357
kotlin {
374
358
explicitApi()
375
359
}
0 commit comments