Gradle with QueryDSL 4.1.4&的IntelliJ [英] Gradle with QueryDSL 4.1.4 & Intellij

查看:1682
本文介绍了Gradle with QueryDSL 4.1.4&的IntelliJ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Spring-Boot 1.5.2项目中重新获得queryDSL 1.4.1的Q类。 IDE是Intellij Ultimate。

I am trying to get my Q Classes for queryDSL 1.4.1 recongised in a Spring-Boot 1.5.2 project. The IDE is 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(该文件夹为空)。

Even though the javaGeneratedSources points to file $buildDir/generated-sources/java (that folder is empty).

构建错误是:

C:\ Users \ User \ IdeaProjects\demo3 \ src \ main \\ _java\com\example\services\EpServiceImpl.java:13:error:找不到符号
import com.example.domain.QEp;
^
符号:class QEp
location:package com.example.domain

我检查其他Stack Overflow回答此处其他但我无法使这些方法起作用。

I check other Stack Overflow answers here and here but I have not been able to get these methods to work.

推荐答案

我建议尝试这个。

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

这篇关于Gradle with QueryDSL 4.1.4&的IntelliJ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆