4

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.

Bosko Mijin
  • 3,287
  • 3
  • 32
  • 45
  • Out of curiosity - which version of grade and intellij are you using? You don't need to add sourceSets anymore – Lesiak Apr 26 '19 at 17:15
  • @Lesiak I'm using eclipse, not idea, but mentioned there that I'm analyzed more explanations, even for idea. Gradle version is 5.4. – Bosko Mijin Apr 26 '19 at 18:18
  • Does it help if you change the srcDir to `build/generated/sources/annotationProcessor/java/` – Lesiak Apr 26 '19 at 19:28
  • @Lesiak Thanks for help, but unfortunately no. Already tried. Tried with all combinations for setting srcDir -> base dir, model dir, annotationProcessor dir as you mentioned.Also tried without setting sourceSet. No changes. Not sure how it is generated, but not included. – Bosko Mijin Apr 26 '19 at 19:37

1 Answers1

9

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.

Bosko Mijin
  • 3,287
  • 3
  • 32
  • 45