OpenFeign / querydsl

Unified Queries for Java
https://querydsl.com
Apache License 2.0
266 stars 39 forks source link

Gradle working example #357

Closed fab918 closed 1 month ago

fab918 commented 8 months ago

Hello,

I spent a few hours trying to get a project running with this version of QueryDSL. My project basically works with queryDsl v4. I'd like to update it, but I've tried everything I can't found on the Internet but and I can't get my Q classes generated with V5 and grandle. The examples on the repo are in Maven only unfortunately.

Is it possible to get help to have a minimal project that generates Q classes with Gradle?

I think it will help other people. Thanks for everything!

DaiYuANg commented 8 months ago

Hey there, only add annotationProcessor in gradle

[versions]
queryDsl = "6.1"

[libraries]
#QueryDSL
queryDSLBom = { group = "io.github.openfeign.querydsl", name = "querydsl-bom", version.ref = "queryDsl" }
queryDslJPA = { group = "io.github.openfeign.querydsl", name = "querydsl-jpa", version.ref = "queryDsl" }
queryDslApt = { group = "io.github.openfeign.querydsl", name = "querydsl-apt", version.ref = "queryDsl" }
queryDslSpatial = { group = "io.github.openfeign.querydsl", name = "querydsl-spatial", version.ref = "queryDsl" }
queryDslGuava = { group = "io.github.openfeign.querydsl", name = "querydsl-guava", version.ref = "queryDsl" }
queryDslCollection = { group = "io.github.openfeign.querydsl", name = "querydsl-collections", version.ref = "queryDsl" }
queryDslCore = { group = "io.github.openfeign.querydsl", name = "querydsl-core", version.ref = "queryDsl" }
queryDslSql = { group = "io.github.openfeign.querydsl", name = "querydsl-sql", version.ref = "queryDsl" }
queryDslSqlCodeGen = { group = "io.github.openfeign.querydsl", name = "querydsl-codegen", version.ref = "queryDsl" }
compileOnly("io.github.openfeign.querydsl:querydsl-apt:${libs.versions.queryDsl.get()}:jpa")
implementation(libs.queryDslJPA)
annotationProcessor("io.github.openfeign.querydsl:querydsl-apt:${libs.versions.queryDsl.get()}:jpa")
implementation(libs.queryDslCore)
implementation(libs.queryDslGuava)
implementation(libs.queryDslCollection)
implementation(libs.queryDslSpatial)
annotationProcessor(libs.jakartaPersistence)
velo commented 7 months ago

@fab918 we need to create a gradle plugin for querydsl.

But I never got to make one.

If you keen on making it happen, I'm more than happy to review and advise.

This might be a good inspiration https://github.com/jOOQ/jOOQ/blob/main/jOOQ-codegen-gradle/src/main/java/org/jooq/codegen/gradle/NamedConfiguration.java

fab918 commented 7 months ago

@DaiYuANg It doesn't work, nothing happens when I run a build with gradle, normally the classes should be generated.

I tried :

compileOnly("io.github.openfeign.querydsl:querydsl-apt:6.2.1:jpa")
annotationProcessor("io.github.openfeign.querydsl:querydsl-apt:6.2.1:jpa")

I've tried the suggested configuration here https://github.com/querydsl/querydsl/issues/3655, in the same way, nothing happens when I build.

I tested with java 17 and 21.

  implementation("io.github.openfeign.querydsl:querydsl-core:6.2.1")
  implementation("io.github.openfeign.querydsl:querydsl-jpa:6.2.1")
  annotationProcessor("io.github.openfeign.querydsl:querydsl-apt:6.2.1:jpa")
  annotationProcessor("jakarta.persistence:jakarta.persistence-api")
  annotationProcessor("jakarta.annotation:jakarta.annotation-api")

@velo Why should we need a plugin to use the library on Gradle?

vidakovic commented 7 months ago

@fab918 ... I am using:

annotationProcessor "com.infobip:infobip-spring-data-jdbc-annotation-processor"

Note: the latest version 9.0.7 is not compatible, but I've created a PR to move all dependencies from "com.querydsl:" to "io.github.openfeign.querydsl:" https://github.com/infobip/infobip-spring-data-querydsl/pull/101.

lucasdistasi commented 2 months ago

Any updates on this? I'm using Kotlin and Gradle and Q classes are not being generated.

velo commented 2 months ago

Needs someone to take charge in this initiative. I don't have the bandwidth

konczdam commented 2 months ago

@lucasdistasi I managed to make it generate the Q classes in a project with Spring Boot, Kotlin Entity classes and Kotlin Gradle file.

plugins {
    val kotlinVersion = "2.0.0"
    kotlin("jvm") version kotlinVersion
    kotlin("plugin.spring") version kotlinVersion
    kotlin("plugin.jpa") version kotlinVersion
    kotlin("kapt") version kotlinVersion

    id("org.springframework.boot") version "3.2.5"
    id("io.spring.dependency-management") version "1.1.4"
}

dependencies {
    val querydslVersion = "6.7"
    implementation("io.github.openfeign.querydsl:querydsl-jpa:$querydslVersion")
    implementation("io.github.openfeign.querydsl:querydsl-sql:$querydslVersion")

    kapt("io.github.openfeign.querydsl:querydsl-apt:$querydslVersion")
    compileOnly("io.github.openfeign.querydsl:querydsl-apt:$querydslVersion:jpa")
}

kapt {
    arguments {
        arg("querydsl.entityAccessors", "true")
    }
}
sourceSets {
    main {
        kotlin {
            srcDir("src/main/kotlin")
        }
    }
    test {
        kotlin {
            srcDir("src/test/kotlin")
        }
    }
}

It generates the Q classes to the build/generated/source/kapt/main folder. To run the class generation, run either of these:

gradle kaptKotlin
gradle build

Hope this helped.

velo commented 1 month ago

Seems no one is working on this, I'm closing to clear the board. Feel free to reopen after a PR is submitted.