【问题标题】:Gradle compile QuerydslJava failedGradle 编译 QuerydslJava 失败
【发布时间】:2018-08-05 21:13:51
【问题描述】:

我正在使用 gradle、springBoot、querydsl 和 mongodb。 添加下一个 gradle 设置跟随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"
}

当我使用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 之后工作正常?

【问题讨论】:

    标签: java mongodb spring-boot gradle querydsl


    【解决方案1】:

    问题出在 pmd 插件中。

    我已经从我的构建./gradlew clean build -x compileQuerydslJava 中排除了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]
        }
    

    现在它可以正常工作了。

    【讨论】:

    • 我有类似的问题并尝试了您的方法。虽然构建通过了 QClasses 没有生成 - 这是有道理的。毕竟-x compileQuerydslJava 跳过了生成它们的过程。 QClass 是为你生成的?
    • 在我的情况下,我在任务 compileQueryDsl 之前遇到了另一个问题,我已经排除了这个任务并找出了错误(它是 pmd)。在您的情况下,您在执行build 任务时看到什么错误?
    • 当我添加 ewerk 插件时,build 任务找不到 JpaAnnotationProcessor 和其他几个依赖项。如果我删除插件 build 成功,但不会生成 QClasses。通过添加插件并使用./gradlew clean build -x compileQuerydslJava 的方法build 通过,但不会生成QClasses。最后,我删除了插件并手动创建了 QClasses。这解决了我的问题。
    • 这不是最好的解决方案。实际上,有很多问题。我认为您应该创建一个单独的问题。因为例如在新的 gradle > 5.0 中,您应该以稍微不同的方式应用查询 dsl 插件。比如: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 }
    猜你喜欢
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多