Querydsl: spring-data-mongodb ๋ฐ gradle๋กœ ์ฟผ๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•

์— ๋งŒ๋“  2020๋…„ 06์›” 21์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: querydsl/querydsl

Querydsl์— ๋Œ€ํ•œ ์ฟผ๋ฆฌ ์œ ํ˜•์„ ์ƒ์„ฑํ•˜๋„๋ก gradle์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. #2444์™€ ๊ฐ™์€ ์กฐ์–ธ์— ๋”ฐ๋ผ ๋‚ด ๊ตฌ์„ฑ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

plugins {
    id 'org.springframework.boot' version '2.3.1.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
    implementation 'org.springframework.boot:spring-boot-starter-web'

    compile 'com.querydsl:querydsl-mongodb:4.3.1'
    annotationProcessor 'com.querydsl:querydsl-apt:4.3.1:morphia'
    annotationProcessor 'org.springframework.boot:spring-boot-starter-data-mongodb'
}

์ฟผ๋ฆฌ ์œ ํ˜•์ด ์ƒ์„ฑ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
Gradle ๋ฒ„์ „: 6.4.1

๋ถˆํ–‰ํžˆ๋„ ๋ฌธ์„œ๋Š” maven์— ๋Œ€ํ•œ ๊ตฌ์„ฑ๋งŒ ์ œ๊ณตํ•˜๋ฉฐ ์›น์˜ ๋‹ค๋ฅธ ๋ชจ๋“  ๊ฐ€์ด๋“œ๋Š” ๋” ์ด์ƒ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์ƒ˜ํ”Œ ์ €์žฅ์†Œ: https://github.com/viktorgt/spring-mongo-querydsl

question

๋ชจ๋“  3 ๋Œ“๊ธ€

์•ˆ๋…•ํ•˜์„ธ์š” @viktorgt ์ด๊ฒƒ์„ ์‹œ๋„ํ•˜์‹ญ์‹œ์˜ค. ๋‚˜๋Š” ์ด๊ฒƒ์œผ๋กœ Q-Classes๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๊ฒƒ์ด ๋‹น์‹ ๊ณผ ์ €๋ฅผ ์œ„ํ•ด ์‹คํ–‰๋˜๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค. ์ฐธ๊ณ  ์ €๋Š” Morphia ์ฃผ์„๊ณผ ์ข…์†์„ฑ์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๋Œ€์‹  @com.querydsl.core.annotations.QueryEntity ๋ฐ build.gradle ์‚ฌ์šฉ

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

dependencies {
   //your general spring data and other spring dependencies
   compileOnly 'com.querydsl:querydsl-apt'
   compile 'com.querydsl:querydsl-mongodb:4.3.1'
   compile 'com.querydsl:querydsl-core'

   annotationProcessor ('com.querydsl:querydsl-apt:4.3.1:general', 'javax.annotation:javax.annotation-api')
}

//Your path can be as per your choice of source directory for the Q-Classes mine is /src/main/generated/

def queryDslOutput = file(new File(projectDir, '/src/main/generated/'))
sourceSets {
    generated {
        java {
            srcDir queryDslOutput
        }
    }
}

compileJava {
    options.compilerArgs << '-s'
    options.compilerArgs << "$projectDir/src/main/generated/"

    doFirst {
        file(new File(projectDir, '/src/main/generated/')).mkdirs();
    }
}

ํŽธ์ง‘ : JPA ์ฃผ์„ ๋˜๋Š” Spring-Data-JPA๋„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
Gradle ๋ฒ„์ „: 6.5

์ถ”์‹ : ์ €๋Š” Github๋ฅผ ์ฒ˜์Œ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด ๋Œ“๊ธ€์„ ์—ฌ๋Ÿฌ ๋ฒˆ ํŽธ์ง‘ํ–ˆ์Šต๋‹ˆ๋‹ค.

@somudas93 ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ์‹ค์ œ๋กœ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค ๐Ÿ‘

์šฐ๋ฆฌ๋Š” ๋˜ํ•œ ์ถ”๊ฐ€ ํ•  ์ˆ˜ delete(files("${projectDir}/src/main/generated/")) ์—์„œ doFirst ์˜ ๋ถ€๋ถ„ compileJava ๋ณ€ํ™”๊ฐ€ ๋ฌด์‹œ๋ฉ๋‹ˆ๋‹ค, ๊ทธ๋ž˜์„œ ์˜ค๋ž˜๋œ ํŒŒ์ผ.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰