Skip to content

Commit

Permalink
[YS-132] chore: QueryDSL 설정 추가 (#26)
Browse files Browse the repository at this point in the history
* chore: add QueryDSL dependency and configuration file

* fix: fix package path structure

* chore: add querydsl to .gitignore
  • Loading branch information
Ji-soo708 authored Jan 12, 2025
1 parent acbfceb commit 6988476
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ application-local.yml
### Kotlin ###
.kotlin
/src/main/resources/application.yml

### QueryDSL ###
generated/
56 changes: 50 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
plugins {
kotlin("jvm") version "1.9.25"
kotlin("plugin.spring") version "1.9.25"
kotlin("plugin.jpa") version "1.9.25"
kotlin("kapt") version "1.9.25"
id("org.springframework.boot") version "3.4.1"
id("io.spring.dependency-management") version "1.1.7"
id("jacoco")
id("org.sonarqube") version "6.0.1.5171"
kotlin("plugin.jpa") version "1.9.25"
}

group = "com.dobby"
Expand All @@ -26,12 +27,17 @@ configurations {
extendsFrom(configurations.annotationProcessor.get())
}
}
val queryDslVersion: String by extra

repositories {
mavenCentral()
maven{url = uri("https://jitpack.io") }
}

kapt {
includeCompileClasspath = false
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa") {
exclude(group = "org.hibernate", module = "hibernate-core")
Expand All @@ -47,9 +53,6 @@ dependencies {
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0")
implementation("org.springframework.cloud:spring-cloud-starter-openfeign")
implementation("io.awspring.cloud:spring-cloud-starter-aws:2.4.4")
implementation("com.github.in-seo:univcert:master-SNAPSHOT") {
exclude(group = "org.hamcrest", module= "harmcest-core")
}
compileOnly("org.projectlombok:lombok")
runtimeOnly("com.mysql:mysql-connector-j")
runtimeOnly("com.h2database:h2")
Expand All @@ -65,6 +68,12 @@ dependencies {
runtimeOnly("io.jsonwebtoken:jjwt-impl:$jjwtVersion")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:$jjwtVersion")

// querydsl
implementation("com.querydsl:querydsl-jpa:5.0.0:jakarta")
kapt("com.querydsl:querydsl-apt:5.0.0:jakarta")
kapt("jakarta.annotation:jakarta.annotation-api")
kapt("jakarta.persistence:jakarta.persistence-api")

val koTestVersion = "5.8.1"
testImplementation("io.kotest:kotest-runner-junit5-jvm:$koTestVersion")
testImplementation("io.kotest:kotest-assertions-core:$koTestVersion")
Expand Down Expand Up @@ -97,6 +106,29 @@ allOpen {
annotation("jakarta.persistence.Embeddable")
}

// querydsl
val generated = file("src/main/generated")
tasks.withType<JavaCompile> {
options.generatedSourceOutputDirectory.set(generated)
}

sourceSets {
main {
kotlin.srcDirs += generated
}
}

tasks.named("clean") {
doLast {
generated.deleteRecursively()
}
}

kapt {
generateStubs = true
}


jacoco {
toolVersion = "0.8.8"
}
Expand Down Expand Up @@ -131,6 +163,11 @@ tasks.jacocoTestReport {
xml.outputLocation.set(file(layout.buildDirectory.dir("reports/jacoco/index.xml").get().asFile))
}

val Qdomains = mutableListOf<String>() // 초기화
for (qPattern in listOf("**/QA", "**/QZ")) {
Qdomains.add("$qPattern*")
}

classDirectories.setFrom(
files(
classDirectories.files.flatMap { dir ->
Expand All @@ -143,7 +180,8 @@ tasks.jacocoTestReport {
"**/domain/model/*",
"**/infrastructure/*",
"**/presentation/*",
"**/util/*"
"**/util/*",
*Qdomains.toTypedArray()
)
}.files
}
Expand All @@ -153,6 +191,11 @@ tasks.jacocoTestReport {
}

tasks.jacocoTestCoverageVerification {
val Qdomains = mutableListOf<String>()
for (qPattern in listOf("**/QA", "**/QZ")) {
Qdomains.add("$qPattern*")
}

violationRules {
rule {
isFailOnViolation = false
Expand All @@ -179,7 +222,8 @@ tasks.jacocoTestCoverageVerification {
"**.domain.model.*",
"**.infrastructure.*",
"**.presentation.*",
"**.util.*"
"**.util.*",
*Qdomains.toTypedArray()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.dobby.backend.infrastructure.database

import com.querydsl.jpa.impl.JPAQueryFactory
import jakarta.persistence.EntityManager
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class QueryDslConfig(
val entityManager: EntityManager
) {
@Bean
fun jpaQueryFactory(): JPAQueryFactory {
return JPAQueryFactory(entityManager)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dobby.backend.infrastructure.database.entity

import AuditingEntity
import com.dobby.backend.infrastructure.database.entity.common.AuditingEntity
import com.dobby.backend.infrastructure.database.entity.enum.VerificationStatus
import jakarta.persistence.*
import java.time.LocalDateTime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.dobby.backend.infrastructure.database.entity.common

import jakarta.persistence.Column
import jakarta.persistence.EntityListeners
import jakarta.persistence.MappedSuperclass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dobby.backend.infrastructure.database.entity.experiment

import AuditingEntity
import com.dobby.backend.infrastructure.database.entity.common.AuditingEntity
import com.dobby.backend.domain.model.experiment.ExperimentImage
import jakarta.persistence.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dobby.backend.infrastructure.database.entity.experiment

import AuditingEntity
import com.dobby.backend.infrastructure.database.entity.common.AuditingEntity
import com.dobby.backend.domain.model.experiment.ExperimentPost
import com.dobby.backend.infrastructure.database.entity.member.MemberEntity
import com.dobby.backend.infrastructure.database.entity.enum.MatchType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dobby.backend.infrastructure.database.entity.member

import AuditingEntity
import com.dobby.backend.infrastructure.database.entity.common.AuditingEntity
import com.dobby.backend.domain.model.member.Member
import com.dobby.backend.infrastructure.database.entity.enum.MemberStatus
import com.dobby.backend.infrastructure.database.entity.enum.ProviderType
Expand Down

0 comments on commit 6988476

Please sign in to comment.