我正在使用gradle,springBoot,querydsl和mongodb。
this article之后添加了下一个gradle设置:

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"
}

当我使用gradle bootRun启动项目时,它工作正常,但是当我仅使用gradle clean build时,在编译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.*;
^

为什么它在构建过程中失败并且在bootRun之后可以正常工作?

最佳答案

问题出在pmd插件中。

我从构建compileQuerydslJava中排除了./gradlew clean build -x compileQuerydslJava任务,并遇到下一个错误

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

所以我为Pmd插件指定了源集
pmd {
        sourceSets = [sourceSets.main]
    }

现在工作正常。

09-10 11:23
查看更多