Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QClass not generated querydslDir in Gradle Setting #3615

Open
Voyager003 opened this issue Oct 30, 2023 · 3 comments
Open

QClass not generated querydslDir in Gradle Setting #3615

Voyager003 opened this issue Oct 30, 2023 · 3 comments
Labels

Comments

@Voyager003
Copy link

Voyager003 commented Oct 30, 2023

Observed vs. expected behavior

After installing the querydsl dependency,
running build-> compileQuerydsl generate a QClass under build/generated/queydsl with the path to def querydsl.

However when run the application, the path of QClass is changed to build/generated/querydsl/generated and
'the error java: Attempt to recreate a file for type ...' occurs.

스크린샷 2023-10-30 오후 5 11 07

it's directory befroe running application.

스크린샷 2023-10-30 오후 5 08 20

it's directory after running application and occur 'java: Attempt to recreate a file for type' error

Steps to reproduce

  1. Add the Gradle settings.
plugins {
    id 'java'
    id 'org.springframework.boot' version '3.1.0'
    id 'io.spring.dependency-management' version '1.1.0'
    id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}

dependencies {
    // Querydsl
    implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
    annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
    annotationProcessor "jakarta.annotation:jakarta.annotation-api"
    annotationProcessor "jakarta.persistence:jakarta.persistence-api"
}

// setting
def querydslDir = "$buildDir/generated/querydsl"

querydsl {
    jpa = true
    querydslSourcesDir = querydslDir
}
sourceSets {
    main.java.srcDir querydslDir
}
compileQuerydsl{
    options.annotationProcessorPath = configurations.querydsl
}
configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
    querydsl.extendsFrom compileClasspath
}

tasks.named('test') {
    useJUnitPlatform()
}
  1. Gradle build and CompileJava
  2. Run the application

Environment

Querydsl version: 5.0.0

Querydsl module: querydsl-jpa, querydsl-apt

Database: H2 DB

JDK: Java 17

Spring Boot: 3.1.0

Additional details

After the path is changed, move the toy to generated and run the application again and it should work.

@Voyager003 Voyager003 added the bug label Oct 30, 2023
@Voyager003 Voyager003 changed the title QFile not generated querydslDir in Gradle Setting QClass not generated querydslDir in Gradle Setting Oct 30, 2023
@rpkyrych
Copy link

@Voyager003 try to remove id "com.ewerk.gradle.plugins.querydsl" version "1.0.10" from plugins and to build again.
It looks like the plugin is outdated and conflicts with querydsl v5

@Voyager003
Copy link
Author

@rpkyrych I fixed to remove plugin as you said, but build is failed and occured this error,

A problem occurred evaluating root project '--'.
Could not find method querydsl() for arguments [build_1nsrjt4d8dqaimc38lgg23yy3$_run_closure4@29dd41d6] on root project '--' of type org.gradle.api.Project.

So I'm using the following settings this stopgap.

def generated = 'src/main/generated'

// add script
clean {
    delete file (generated)
}

querydsl {
    jpa = true
    querydslSourcesDir = generated
}
sourceSets {
    main.java.srcDir generated
}

// add script
tasks.compileQuerydsl.dependsOn(clean);

compileQuerydsl{
    options.annotationProcessorPath = configurations.querydsl
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
    querydsl.extendsFrom compileClasspath
}

Add a QType removal action to the Querydsl-related plugin removal and clean actions to create a new QType on gradle task - build.

@rpkyrych
Copy link

Hey, @Voyager003 here is my working configuration without the plugin with Spring, Lombok and Mapstruct.
It might help you.

plugins {
    `java-library`
    id("org.springframework.boot") version "3.2.0"
    id("io.spring.dependency-management") version "1.1.4"
    id("io.freefair.lombok") version "8.4"
}

...

val lombokVersion = "1.18.30"
val lombokMapstructBindingVersion = "0.2.0"
val mapstructVersion = "1.6.0.Beta1"
val querydslVersion = "5.0.0:jakarta"

dependencies {
   // some spring boot dependencies here   

    api("com.querydsl:querydsl-jpa:${querydslVersion}")
    api("org.mapstruct:mapstruct:${mapstructVersion}")
    api("org.projectlombok:lombok:${lombokVersion}")

    annotationProcessor("com.querydsl:querydsl-apt:$querydslVersion")
    annotationProcessor("jakarta.persistence:jakarta.persistence-api:3.1.0")
    annotationProcessor("org.mapstruct:mapstruct-processor:$mapstructVersion")
    annotationProcessor("org.projectlombok:lombok:$lombokVersion")
    annotationProcessor("org.projectlombok:lombok-mapstruct-binding:$lombokMapstructBindingVersion")
}

and nothing more in it related to querydsl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants