I searched a lot regarding the configuration of QueryDSL
with Gradle
.
I would like to configure the annotation processor, to use a specific annotation @Generated
on the generated classes.
- But I could only find this link here: Gradle : Unable to generate QueryDSL classes. This helped me with some details.
- And the official documentation showing the options available to use: https://querydsl.com/static/querydsl/latest/reference/html/ch03s03.html (3.3.2. Customization).
This is my build.gradle
(resumed):
plugins {
id 'java'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.6'
annotationProcessor 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.6'
implementation 'com.querydsl:querydsl-jpa:5.0.0'
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jpa"
}
compileJava {
finalizedBy 'generateQueryDSL'
}
task generateQueryDSL(type: JavaCompile) {
source = sourceSets.main.java.srcDirs
classpath = sourceSets.main.compileClasspath
getDestinationDirectory().set(file("$buildDir/generated/sources/annotationProcessor/java/main"))
options.annotationProcessorPath = configurations.annotationProcessor
options.compilerArgs = [
'-proc:only',
'-processor',
'com.querydsl.apt.jpa.JPAAnnotationProcessor',
'-Aquerydsl.generatedAnnotationClass=com.querydsl.core.annotations.Generated'
]
}
Is there an easier way to configure the annotation processor? I had a LOT of troubles with this approach, because the original method keeps changing the file with the OLD annotation, because I can't replace this old behavior. And with this, there are tasks (or steps inside the "compileJava" task) that I can't remove or override.