Skip to content

Instantly share code, notes, and snippets.

@djkeh
Created August 16, 2022 01:38
Show Gist options
  • Save djkeh/92887c19801924d12b42dc4a49c2b7f8 to your computer and use it in GitHub Desktop.
Save djkeh/92887c19801924d12b42dc4a49c2b7f8 to your computer and use it in GitHub Desktop.
Querydsl Configuration on Gradle - Spring Boot 2.7 + Querydsl 5.0.0 + Gradle 7.4.1
### Querydsl
/src/main/generated
plugins {
id 'org.springframework.boot' version '2.7.2'
id 'io.spring.dependency-management' version '1.0.12.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.01-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// Querydsl dependencies
implementation "com.querydsl:querydsl-jpa"
implementation "com.querydsl:querydsl-core"
implementation "com.querydsl:querydsl-collections"
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jpa" // querydsl JPAAnnotationProcessor
annotationProcessor "jakarta.annotation:jakarta.annotation-api" // This prevents java.lang.NoClassDefFoundError
annotationProcessor "jakarta.persistence:jakarta.persistence-api" // This prevents java.lang.NoClassDefFoundError
}
tasks.named('test') {
useJUnitPlatform()
}
//// Additional Querydsl configuration
def generated = 'src/main/generated'
// Querydsl - Place QClass files to the specific directory
tasks.withType(JavaCompile) {
options.getGeneratedSourceOutputDirectory().set(file(generated))
}
// Querydsl - Add QClass file path to the java source set
sourceSets {
main.java.srcDirs += [ generated ]
}
// Querydsl - Remove QClass directory when doing `gradle clean`
clean {
delete file(generated)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment