Skip to content

Commit 98c144a

Browse files
authored
Fix file generation issue on rebuild (#862) (#878)
### Overview - Follow up on @IceBlizz6 comment from PR #865 The change moves responsibilities of generating Q classes to each individual module, whether that module is in a local project or a library dependency. If a module is expecting a class (like a base entity `@MappedSuperclass`) to be used in a client project, it must incorporate KSP processing and package the generated Q class in its artifact. To achieve this, the superclasses are still stored as a `QueryModel`, but the files are not written if the `containingFile` is null. ### Testing Local project (and 2 test projects from the original ticket) were updated with this change and ran all Q class generation successfully for every build
2 parents bd7767c + 5db48e0 commit 98c144a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

querydsl-tooling/querydsl-ksp-codegen/src/main/kotlin/com/querydsl/ksp/codegen/QueryDslProcessor.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class QueryDslProcessor(
2828
override fun finish() {
2929
val models = typeProcessor.process()
3030
models.forEach { model ->
31+
if (model.originatingFile == null) {
32+
// skip models without originating file. This happens when the model is from a compiled dependency,
33+
// so we don't have access to the source file. It is expected the Q class is packaged alongside the
34+
// compiled dependency.
35+
return@forEach
36+
}
37+
3138
val typeSpec = QueryModelRenderer.render(model)
3239
FileSpec.builder(model.className)
3340
.indent(settings.indent)
@@ -36,7 +43,7 @@ class QueryDslProcessor(
3643
.writeTo(
3744
codeGenerator = codeGenerator,
3845
aggregating = false,
39-
originatingKSFiles = listOfNotNull(model.originatingFile)
46+
originatingKSFiles = listOf(model.originatingFile)
4047
)
4148
}
4249
}

0 commit comments

Comments
 (0)