spring-boothibernatejpabuild.gradlequerydsl

Spring boot 3 hibernate 6 Querydsl Gradle Unable to load class 'jakarta.persistence.Entity'


I have project with spring-boot:3.1.4 and query-dsl:5.0.0 build.gradle

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.1.4'
}

java {
    sourceCompatibility = '17'
}
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'com.querydsl:querydsl-apt:5.0.0:jakarta'
    implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
    annotationProcessor 'com.querydsl:querydsl-apt:5.0.0:jakarta'
}

When I tried to build project, this error happened. Here is the build log

FAILURE: Build failed with an exception.

What went wrong: Execution failed for task ':compileJava'. java.lang.NoClassDefFoundError: jakarta/persistence/Entity


Solution

  • You're missing a dependency.

    Try to add this to your dependencies

    annotationProcessor 'jakarta.persistence:jakarta.persistence-api:3.1.0'