diff --git a/build.gradle b/build.gradle index 66882d5..69fe1d3 100644 --- a/build.gradle +++ b/build.gradle @@ -306,35 +306,47 @@ tasks.withType(JavaCompile) { // querydsl //-----------------------------------------------------------------------------------// def querydslDir = "$buildDir/generated" -querydsl { - jpa = true - querydslSourcesDir = querydslDir -} + +// querydsl 적용 sourceSets { main { java { - //srcDirs = ["$projectDir/src/main/java", querydslDir] - srcDir querydslDir + srcDirs = ["$projectDir/src/main/java", querydslDir] } } } + +querydsl { + jpa = true + querydslSourcesDir = querydslDir +} + configurations { compileOnly { extendsFrom annotationProcessor } querydsl.extendsFrom compileClasspath } + compileQuerydsl { options.annotationProcessorPath = configurations.querydsl } +// build시 querydsl 삭제후 재 컴파일 +compileQuerydsl.doFirst { + if(file(querydslDir).exists()) + delete(file(querydslDir)) +} + +// build시 querydsl 적용 compileJava { options.compilerArgs << '-s' options.compilerArgs << "$buildDir/generated/" doFirst { - delete(files("${buildDir}/generated/")) - file(new File(buildDir, '/generated/')).mkdirs(); + if(file(querydslDir).exists()) + delete(file(querydslDir)) + file(querydslDir).mkdirs(); } } //-----------------------------------------------------------------------------------// diff --git a/src/test/java/com/xit/biz/ctgy/repository/RepositoryTest.java b/src/test/java/com/xit/biz/ctgy/repository/RepositoryTest.java new file mode 100644 index 0000000..069ea25 --- /dev/null +++ b/src/test/java/com/xit/biz/ctgy/repository/RepositoryTest.java @@ -0,0 +1,57 @@ +package com.xit.biz.ctgy.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.xit.biz.ctgy.entity.MinSimsa680; +import com.xit.biz.ctgy.entity.QMinSimsa680; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +import javax.persistence.EntityManager; +import javax.transaction.Transactional; + +import static com.xit.biz.ctgy.entity.QMinSimsa680.minSimsa680; + +@SpringBootTest +@Transactional +@ActiveProfiles({"dev"}) +@Slf4j +public class RepositoryTest { + + @Autowired + EntityManager em; + + private JPAQueryFactory queryFactory; + +// @BeforeAll +// void beforeAll(){ +// log.debug("initializing..."); +// } + +// @AfterAll +// void afterAll(){ +// log.debug("...shutdown"); +// } + + @BeforeEach + void beforeEach(){ + log.debug("biz start..."); + queryFactory = new JPAQueryFactory(em); + } + + @AfterEach + void afterEach(){ + log.debug("... biz end"); + } + + @Test + void querydslTest() { + //QMinSimsa680 qMinSimsa680 = new QMinSimsa680("minSimsa680"); + MinSimsa680 simsa680 = queryFactory.selectFrom(minSimsa680) + .where(minSimsa680.msMaincode.eq(300297013L)) + .fetchOne(); + log.debug("##################################{}",simsa680); + } +}