Skip to content

Commit

Permalink
Fix file generation issue on rebuild (#862) (#878)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
IceBlizz6 authored Feb 11, 2025
2 parents bd7767c + 5db48e0 commit 98c144a
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class QueryDslProcessor(
override fun finish() {
val models = typeProcessor.process()
models.forEach { model ->
if (model.originatingFile == null) {
// skip models without originating file. This happens when the model is from a compiled dependency,
// so we don't have access to the source file. It is expected the Q class is packaged alongside the
// compiled dependency.
return@forEach
}

val typeSpec = QueryModelRenderer.render(model)
FileSpec.builder(model.className)
.indent(settings.indent)
Expand All @@ -36,7 +43,7 @@ class QueryDslProcessor(
.writeTo(
codeGenerator = codeGenerator,
aggregating = false,
originatingKSFiles = listOfNotNull(model.originatingFile)
originatingKSFiles = listOf(model.originatingFile)
)
}
}
Expand Down

0 comments on commit 98c144a

Please sign in to comment.