|
| 1 | +# KSP for QueryDSL |
| 2 | +Provides a lightweight and efficient way to generate `Q` classes for QueryDSL in Kotlin projects. |
| 3 | +Supports only jakarta annotations. |
| 4 | + |
| 5 | +Let us know if you want support for other annotations. |
| 6 | + |
| 7 | +## Setup |
| 8 | + |
| 9 | +### Gradle |
| 10 | +Add the KSP plugin and dependency for the processor in your `build.gradle.kts` |
| 11 | + |
| 12 | +```kotlin |
| 13 | +plugins { |
| 14 | + kotlin("jvm") version "2.1.21" |
| 15 | + id("com.google.devtools.ksp") version "2.1.21-2.0.2" |
| 16 | + kotlin("plugin.jpa") |
| 17 | + kotlin("plugin.serialization") |
| 18 | +} |
| 19 | + |
| 20 | +repositories { |
| 21 | + mavenCentral() |
| 22 | +} |
| 23 | + |
| 24 | +dependencies { |
| 25 | + implementation("jakarta.persistence:jakarta.persistence-api:${jpaVersion}") |
| 26 | + implementation("io.github.openfeign.querydsl:querydsl-jpa:${querydslVersion}") |
| 27 | + ksp("io.github.openfeign.querydsl:querydsl-ksp-codegen:${querydslVersion}") |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +And it may be necessary to [make your IDE aware of KSP generated code](https://kotlinlang.org/docs/ksp-quickstart.html#make-ide-aware-of-generated-code) |
| 32 | + |
| 33 | +```kotlin |
| 34 | +kotlin { |
| 35 | + sourceSets.main { |
| 36 | + kotlin.srcDir("build/generated/ksp/main/kotlin") |
| 37 | + } |
| 38 | + sourceSets.test { |
| 39 | + kotlin.srcDir("build/generated/ksp/test/kotlin") |
| 40 | + } |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +### Settings (all optional) |
| 45 | + |
| 46 | +| Name | Type | Default | Description | |
| 47 | +|:---------------|:----------------------------|:--------------|:------| |
| 48 | +|enable |Boolean |true |Set to false will disable processing| |
| 49 | +|indent |String |" " (4 spaces)|Indent used in generated code files| |
| 50 | +|prefix |String |"Q" |Prefix applied to generated classes| |
| 51 | +|suffix |String |"" |Suffix applied to generated classes| |
| 52 | +|packageSuffix |String |"" |Suffix applied to package name of generated classes| |
| 53 | +|excludedPackages|String (comma separated list)|"" |List of packages that will be skipped in processing| |
| 54 | +|excludedClasses |String (comma separated list)|"" |List of classes that will not be processed| |
| 55 | +|includedPackages|String (comma separated list)|"" |List of packages included, empty means it will include everything| |
| 56 | +|includedClasses |String (comma separated list)|"" |List of classes included, empty means it will include all| |
| 57 | + |
| 58 | +Settings must be prefixed with 'querydsl.' |
| 59 | + |
| 60 | +Add into your `build.gradle.kts` to configure. |
| 61 | + |
| 62 | +```kotlin |
| 63 | +// Example |
| 64 | +ksp { |
| 65 | + arg("querydsl.prefix", "QQ") |
| 66 | + arg("querydsl.excludedPackages", "com.example, com.sample") |
| 67 | +} |
| 68 | +``` |
0 commit comments