티스토리 뷰

Case 1

Spring Boot 3.0.0

Kotlin

Gradle 7.6 (kotlin)

 

spring 3.0.0 부터 javax에서 jakarta를 사용하면서 기존 코드들을 그대로 사용하면 호환성 문제가 있음.

그렇다고 많은부분이 바뀌는건 아니고 build.gradle 의존성만 조금 바꿔주면 된다.

plugins {
   ...
    kotlin("kapt")
}

dependencies {
	...
    annotationProcessor("jakarta.persistence:jakarta.persistence-api")
    annotationProcessor("jakarta.annotation:jakarta.annotation-api")
    // https://mvnrepository.com/artifact/com.querydsl/querydsl-jpa
    implementation("com.querydsl:querydsl-jpa:5.0.0:jakarta")
    kapt("com.querydsl:querydsl-apt:5.0.0:jakarta")
}

QClass 생성

QClass 저장 위치

build/generated/source/kapt/main

reference

https://shanepark.tistory.com/421

https://gaemi606.tistory.com/entry/Spring-Boot-Querydsl-%EC%B6%94%EA%B0%80-Gradle-7x

https://www.inflearn.com/questions/702346/java-lang-classnotfoundexception-javax-persistence-entity-%EC%98%A4%EB%A5%98-%EC%A7%88%EB%AC%B8%EC%9E%85%EB%8B%88%EB%8B%A4

 

Case 2

spring 2.x.x

kotlin

gradle

plugins {
	kotlin("plugin.jpa") version "1.2.71"
    ...
}

allOpen {
	annotation("javax.persistence.Entity")
	annotation("javax.persistence.MappedSuperclass")
}

// 전역변수 (queryDSL 버전)
val querydslVersion = "4.4.0"

dependencies {
	implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    
	runtimeOnly("mysql:mysql-connector-java")
    
    //query-dsl 의존성
	implementation("com.querydsl:querydsl-jpa:$querydslVersion")
	kapt("com.querydsl:querydsl-apt:$querydslVersion:jpa")
    ...
}

 

Case 3

Java

Gradle

plugin {
  //querydsl 추가
  id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
  ...
}

dependencies {
	//query-dsl
	implementation 'com.querydsl:querydsl-jpa'
    ...
}

//querydsl 추가 시작
def querydslDir = "$buildDir/generated/querydsl"
querydsl {
	jpa = true
	querydslSourcesDir = querydslDir
}
sourceSets {
	main.java.srcDir querydslDir
}
configurations {
	querydsl.extendsFrom compileClasspath
}
compileQuerydsl {
	options.annotationProcessorPath = configurations.querydsl
}
//querydsl 추가 끝

 

QClass 생성하기

kaptKotlin 실행

 

 

----------------------------------- 가급적이면 intellij + gradle 을 사용합니다 -----------------------------

Case 4

Maven

eclipse

java

<!-- production database에 접근하기위한 의존성 -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- jpa 사용하기 위한 의존성 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- queryDSL apt -->
<dependency>
    <groupId>com.querydsl</groupId>
    <artifactId>querydsl-apt</artifactId>
    <version>4.2.1</version>
</dependency>		
<!-- queryDSL jpa -->
<dependency>
    <groupId>com.querydsl</groupId>
    <artifactId>querydsl-jpa</artifactId>
    <version>4.2.1</version>
</dependency>

plugin 추가(pom.xml)

<project>
  <build>
  <plugins>
    ...
    <plugin>
      <groupId>com.mysema.maven</groupId>
      <artifactId>apt-maven-plugin</artifactId>
      <version>1.1.3</version>
      <executions>
        <execution>
          <goals>
            <goal>process</goal>
          </goals>
          <configuration>
            <outputDirectory>target/generated-sources/java</outputDirectory>
            <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
          </configuration>
        </execution>
      </executions>
    </plugin>
    ...
  </plugins>
  </build>
</project>

 

QClass생성하기

 

QClass 경로를 못잡을경우

 

 

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함