Home > Software design >  Can't generate Q classes with Spring Boot 3, Jakarta Persistence, QueryDql and Gradle
Can't generate Q classes with Spring Boot 3, Jakarta Persistence, QueryDql and Gradle

Time:01-17

I'm trying to generate q-classes using Spring Boot 3, with Jakarta Persistence, QueryDsl, Gradle and Intellij. But I can't generate q-classes after running ./gradlew clean build. After build, I'm receiving this error: Unable to load class 'jakarta.persistence.Entity'. This is an unexpected error. Please file a bug containing the idea.log file. I searched the internet, but I didn't find an answer to resolve my problem, because Spring Boot version 3 is recent.

Can someone help me?

There's my build.gradle


plugins {
    id 'org.springframework.boot' version '3.0.1'
    id 'io.spring.dependency-management' version '1.1.0'
    id 'java'
}

group = 'br.com.sammubr'
version = '0.0.1-SNAPSHOT'

java {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

ext {
    set('springCloudVersion', "2022.0.0")
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

def queryDslVersion = '5.0.0'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    runtimeOnly 'mysql:mysql-connector-java'
    testImplementation 'org.springframework.security:spring-security-test'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
    implementation 'io.micrometer:micrometer-registry-prometheus'
    implementation("io.jsonwebtoken:jjwt-api:0.11.5")
    runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.5")
    runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5")
    testImplementation 'org.testcontainers:testcontainers:1.17.5'
    testImplementation 'org.testcontainers:mysql:1.17.5'
    implementation 'com.lowagie:itext:2.1.7'
    implementation 'com.github.wmixvideo:nfe:4.0.1'
    implementation 'net.sf.jasperreports:jasperreports:6.20.0'
    implementation 'com.google.zxing:core:3.5.1'
    implementation 'net.sourceforge.barbecue:barbecue:1.5-beta1'
    implementation("com.querydsl:querydsl-core:${queryDslVersion}")
    implementation("com.querydsl:querydsl-jpa:${queryDslVersion}")
    implementation('org.springframework.cloud:spring-cloud-starter-stream-rabbit')
    implementation("com.github.ben-manes.caffeine:caffeine")
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor(
            "com.querydsl:querydsl-apt:${queryDslVersion}:jakarta",
            "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final",
            "org.projectlombok:lombok"
    )
}

tasks.named('test') {
    useJUnitPlatform()
}

Sample of my entities classes:

package br.com.sammubr.admin.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Entity
@Table(name = "activity")
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Activity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    @NotNull
    @Size(max = 100)
    @Column(name = "description", length = 100, nullable = false)
    private String description;

}

CodePudding user response:

I finally got!

It is necessary to use these dependencies:

    implementation("com.querydsl:querydsl-core:${queryDslVersion}")
    implementation("com.querydsl:querydsl-jpa:${queryDslVersion}:jakarta")
    ...
    annotationProcessor(
            "com.querydsl:querydsl-apt:${queryDslVersion}:jakarta",
            "jakarta.persistence:jakarta.persistence-api:3.1.0",
            ...
    )

Then run ./gradlew clean build and q-classes will appear in folder build/generated/annotationProcessor

  • Related