Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

querydsl generated q source code is not imported correctly

I am trying to add querydsl to existing system, but I have problem with getting generated Q source for compiling. I've read several similar problems and explanations (https://spring.io/blog/2015/09/04/what-s-new-in-spring-data-release-gosling#querydsl-web-support, https://blog.jdriven.com/2018/10/using-querydsl-annotation-processor-with-gradle-and-intellij-idea/ (even that this is related to idea)), almost every stack overflow question for querydsl ...

Here is part of my build.gradle which describes what the problem is:

ext {
  ... 
  querydslVersion = '4.2.1'
}

sourceSets {
    generated {
       java {
            srcDirs = [ 'build/generated' ]
        }
    }
    main {
        java {
            srcDirs = [ 'src/main/java' ]
        }
    }
}

...

dependencies {
    ...
    compile("com.querydsl:querydsl-core:${querydslVersion}")
    compile("com.querydsl:querydsl-jpa:${querydslVersion}")
    compile "com.querydsl:querydsl-apt:$querydslVersion:jpa"
    compileOnly group: 'org.projectlombok', name: 'lombok'
    annotationProcessor(
        "com.querydsl:querydsl-apt:${querydslVersion}:jpa",
        "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final",
        "javax.annotation:javax.annotation-api:1.3.2",
        "org.projectlombok:lombok"
    )
}

When I am trying to build, I am getting error: cannot find symbol QuerydslBinderCustomizer<QSample> in the repository class. QSample.java is generated according the model Sample and it is located to

/build/generated/sources/annotationProcessor/java/main/com/prep/ws/model/QSample.java.

Since that this is located into build folder, I am confused why this is not visible for IDE and gradle.

I am not sure what I am doing wrong.

like image 241
Bosko Mijin Avatar asked Oct 16 '25 13:10

Bosko Mijin


1 Answers

After many tries, I've managed that querydsl working (and it working well). I am posting this answer in case that somebody else has same kind of problems. In my case, I had to change sourceSet to point directly on annotationProcessor/java/main. After that everything working as it is expected.

sourceSets.main.java.srcDirs = ['build/generated/sources/annotationProcessor/java/main','src/main/java']

Pointing on build/generated, build/generated/sources/annotationProcessor or build/generated/sources/annotationProcessor/java not working.

like image 127
Bosko Mijin Avatar answered Oct 18 '25 06:10

Bosko Mijin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!