diff --git a/.gitignore b/.gitignore index bf9eeb1d..4b05952c 100644 --- a/.gitignore +++ b/.gitignore @@ -180,4 +180,7 @@ Temporary Items .idea/ # Ignore application-local.yml -src/main/resources/application-local.yml \ No newline at end of file +src/main/resources/application-local.yml + +## Ignore Qclass +src/main/generated/querydsl diff --git a/build.gradle b/build.gradle index dd665e45..b0225719 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,9 @@ configurations { compileOnly { extendsFrom annotationProcessor } + + // Configure libraries related to QueryDSL to be required only at compile-time and add QueryDSL configuration to the compile classpath. + querydsl.extendsFrom compileClasspath } repositories { @@ -25,6 +28,11 @@ repositories { maven { url "https://repo.spring.io/snapshot" } } +// Set global variables used in the project +ext { + set('queryDslVersion', "5.0.0") +} + dependencies { // Spring implementation 'org.springframework.boot:spring-boot-starter-web' @@ -74,9 +82,15 @@ dependencies { implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.4.4' implementation 'io.awspring.cloud:spring-cloud-starter-aws-secrets-manager-config:2.4.4' - //coolsms + // coolsms implementation 'net.nurigo:sdk:4.3.0' implementation 'net.nurigo:javaSDK:2.2' + + // QueryDSL + implementation "com.querydsl:querydsl-jpa:${queryDslVersion}:jakarta" + annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}:jakarta" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" } jar { @@ -85,4 +99,23 @@ jar { tasks.named('test') { useJUnitPlatform() -} \ No newline at end of file +} + +// Set the directory path where the Q-Class will be generated. +def queryDslSrcDir = 'src/main/generated/querydsl/' + +// When executing the JavaCompile task, set the output directory for the generated source code to queryDslSrcDir +tasks.withType(JavaCompile).configureEach { + options.getGeneratedSourceOutputDirectory().set(file(queryDslSrcDir)) +} + +// Add the Q-Class files to the directory path recognized as source code. +// This ensures that the Q-Class is treated as a regular Java class and included in the classpath during compilation and execution. +sourceSets { + main.java.srcDirs += [queryDslSrcDir] +} + +// Configure the clean task to delete the specified directory, automatically removing the generated Q-Class. +clean { + delete file(queryDslSrcDir) +} diff --git a/src/main/java/com/beat/global/common/config/QueryDslConfig.java b/src/main/java/com/beat/global/common/config/QueryDslConfig.java new file mode 100644 index 00000000..69ef11ac --- /dev/null +++ b/src/main/java/com/beat/global/common/config/QueryDslConfig.java @@ -0,0 +1,20 @@ +package com.beat.global.common.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.querydsl.jpa.impl.JPAQueryFactory; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; + +@Configuration +public class QueryDslConfig { + @PersistenceContext + private EntityManager em; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(em); + } +}