0

I'm using gradle, springBoot, querydsl and mongodb. Added next gradle settings follow this article:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:1.0.9"
    }
}

apply plugin: 'com.ewerk.gradle.plugins.querydsl'

sourceSets {
    main {
        java {
            srcDir "$buildDir/generated/source/app/main"
        }
    }
}

dependencies {
    compile "com.querydsl:querydsl-mongodb:4.1.4"
    compileOnly "com.querydsl:querydsl-apt:4.1.4"
}

querydsl {
    springDataMongo = true
    querydslSourcesDir = "$buildDir/generated/source/app/main"
}

It works fine when I start project using gradle bootRun, but when I'm just using gradle clean build it fails when compiling querydsl.

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileQuerydslJava'.
> Compilation failed with exit code 1; see the compiler error output for details.

/Volumes/DATA/notification-service/app/build/generated/source/app/main/net/platform/notification/domain/impl/entity/QNotification.java:76: error: cannot find symbol
    public QNotification(Path<? extends Notification> path) {
                         ^
  symbol:   class Path
  location: class QNotification
/Volumes/DATA/notification-service/app/build/generated/source/app/main/net/platform/notification/domain/impl/entity/QNotification.java:76: error: cannot find symbol
    public QNotification(Path<? extends Notification> path) {
                                        ^
  symbol:   class Notification
  location: class QNotification
/Volumes/DATA/notification-service/app/build/generated/source/app/main/net/platform/notification/domain/impl/entity/QNotification.java:80: error: cannot find symbol
    public QNotification(PathMetadata metadata) {
                         ^
  symbol:   class PathMetadata
  location: class QNotification
/Volumes/DATA/notification-service/app/build/generated/source/app/main/net/platform/notification/domain/impl/entity/QNotification.java:5: error: package com.querydsl.core.types.dsl does not exist
import com.querydsl.core.types.dsl.*;
^

Why it fails during build and works fine after bootRun ?

Max
  • 766
  • 9
  • 19

1 Answers1

0

The issue was in pmd plugin.

I've excluded compileQuerydslJava task from my build ./gradlew clean build -x compileQuerydslJava and got next error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:pmdQuerydsl'.
> 46 PMD rule violations were found. See the report at: file:///Volumes/DATA/notification-service/app/build/reports/pmd/querydsl.html

So I specified source set for pmd plugin

pmd {
        sourceSets = [sourceSets.main]
    }

And now it works fine.

Max
  • 766
  • 9
  • 19
  • I have a similar problem and tried your approach. Although the build passed the QClasses were not generated - which makes sense. After all `-x compileQuerydslJava` skips the process which generates them. The QClasses were generated for you? – Ernani Jun 19 '19 at 15:47
  • In my case I had another issue before task compileQueryDsl, I've excluded this task and figured out what the error (it was pmd). In your case, what error do you see when execute `build` task? – Max Jun 19 '19 at 15:57
  • When I add the ewerk plugin the `build` task can't find `JpaAnnotationProcessor` and several other dependencies. If I remove the plugin the `build` is successful, but the QClasses are not generated. By adding the plugin and using your approach of `./gradlew clean build -x compileQuerydslJava` the `build` passes, but the QClasses are not generated. In the end I removed the plugin and created the QClasses by hand. That solved my problem. – Ernani Jun 24 '19 at 11:13
  • It's not the best solution. Actually, there are a lot of questions. I think you should create a separate question. Because for example in new gradle > 5.0 you should apply query dsl plugin in a little bit different way. Something like: `apply plugin: 'com.ewerk.gradle.plugins.querydsl' dependencies { annotationProcessor 'com.querydsl:querydsl-apt' } querydsl { jpa = true querydslSourcesDir = "$buildDir/generated/sources/annotationProcessor/java/main" } compileQuerydsl { options.annotationProcessorPath = configurations.querydsl }` – Max Jun 24 '19 at 13:05
  • @ernani, pls take a look here https://stackoverflow.com/questions/53913274/querydsl-annotation-processor-issue-after-upgrade-to-gradle-5 – Max Jun 24 '19 at 13:11