Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] #286 - QueryDSL 세팅 완료 #287

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,7 @@ Temporary Items
.idea/

# Ignore application-local.yml
src/main/resources/application-local.yml
src/main/resources/application-local.yml

## Ignore Qclass
src/main/generated/querydsl
37 changes: 35 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'
Expand Down Expand Up @@ -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 {
Expand All @@ -85,4 +99,23 @@ jar {

tasks.named('test') {
useJUnitPlatform()
}
}

// 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)
}
20 changes: 20 additions & 0 deletions src/main/java/com/beat/global/common/config/QueryDslConfig.java
Original file line number Diff line number Diff line change
@@ -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);
}
}