【问题标题】:Gradle with QueryDSL 4.1.4 & Intellij使用 QueryDSL 4.1.4 和 Intellij 的 Gradle
【发布时间】:2018-04-11 22:36:05
【问题描述】:

我试图让我的 queryDSL 1.4.1 的 Q 类在 Spring-Boot 1.5.2 项目中得到认可。 IDE 是 Intellij Ultimate。

build.gradle

buildscript {
ext {
    springBootVersion = '1.5.2.RELEASE'
    }
repositories {
    mavenCentral()
    }
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

plugins {
    id 'net.ltgt.apt' version '0.8'
    id 'java'
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'idea'

version = '0.0.5-SNAPSHOT'
sourceCompatibility = 1.8

ext {
    queryDslVersion = '4.1.4'
    javaGeneratedSources = file("$buildDir/generated-sources/java")
}

compileJava {
    doFirst {
        javaGeneratedSources.mkdirs()
    }
    options.compilerArgs += [
            '-parameters', '-s', javaGeneratedSources
    ]
}

idea {
    module {
        sourceDirs += file('generated/')
        generatedSourceDirs += file('generated/')
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-jdbc')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-mail:1.5.7.RELEASE')
    compile ("org.thymeleaf.extras:thymeleaf-extras-springsecurity4:3.0.0.RELEASE")
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: '1.5.2.RELEASE'
    compile group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity4', version: '2.1.2.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '1.5.2.RELEASE'
    compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.4.0")

    compile group: 'org.hibernate', name: 'hibernate-java8'

    compile "com.querydsl:querydsl-root:$queryDslVersion"
    compile "com.querydsl:querydsl-jpa:$queryDslVersion"
    compileOnly "com.querydsl:querydsl-apt:$queryDslVersion:jpa"

    compile("org.springframework.boot:spring-boot-devtools")
    compile('mysql:mysql-connector-java')
    testCompile('org.hsqldb:hsqldb')
    testCompile('org.springframework.boot:spring-boot-starter-test')
 }

Q 类在以下位置生成:

build\generated\source\apt\main\generated\com\example\domain

即使 javaGeneratedSources 指向文件 $buildDir/generated-sources/java(那个文件夹是空的)。

构建错误是:

C:\Users\User\IdeaProjects\demo3\src\main\java\com\example\services\EpServiceImpl.java:13: error: cannot find symbol import com.example.domain.QEp; ^ symbol: class QEp location: package com.example.domain

我查看了其他 Stack Overflow 答案 herehere,但我无法让这些方法发挥作用。

【问题讨论】:

    标签: spring spring-boot intellij-idea gradle querydsl


    【解决方案1】:

    如果您的 Gradle 高于 5,它将无法工作。 https://github.com/ewerk/gradle-plugins/issues/116

    【讨论】:

      【解决方案2】:

      我建议尝试一下。

      buildscript {
          ext {
              querydslVersion    = "4.1.4"
              metaModelsSourcesDir = file("metamodels")   
          }
      }
      
      configurations {
          querydslapt
      }
      
      sourceSets {
          main {
              java {
                  srcDir metaModelsSourcesDir
              }
          }
      }
      
      
      task querymodels(type: JavaCompile, group: 'build') {
          doFirst {
              delete metaModelsSourcesDir;
              metaModelsSourcesDir.mkdirs();
          }
      
          classpath = configurations.compile + configurations.querydslapt
          destinationDir = metaModelsSourcesDir
      
          source = sourceSets.main.java
          options.compilerArgs = [
                  "-proc:only",
                  "-processor", "com.querydsl.apt.jpa.JPAAnnotationProcessor",
                  "-s", metaModelsSourcesDir
          ]
      }
      
      dependencies {
          compile("com.querydsl:querydsl-core:${querydslVersion}")
          compile("com.querydsl:querydsl-jpa:${querydslVersion}")
      
          querydslapt("com.querydsl:querydsl-apt:${querydslVersion}")
      }
      

      【讨论】:

        猜你喜欢
        • 2015-06-23
        • 2016-11-16
        • 1970-01-01
        • 2014-05-11
        • 2019-03-22
        • 2021-05-08
        • 2016-12-13
        • 2020-10-12
        • 2018-11-24
        相关资源
        最近更新 更多