IntelliJ 15与QueryDSL和Gradle [英] IntelliJ 15 with QueryDSL and Gradle

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

问题描述

我在IntelliJ 15中使用了gradle 2.3和QueryDSL 4.1.3的Spring-boot 1.4项目,因为我的实体没有被Querydsl构建到Q类中,所以不会生成。我有以下内容:

  buildscript {
ext {
springBootVersion ='1.4.0.BUILD- SNAPSHOT'
querydslVersion ='4.1.3'
}
存储库{
mavenCentral()
maven {urlhttps://repo.spring.io/snapshot }
maven {urlhttps://repo.spring.io/milestone}
maven {urlhttps://plugins.gradle.org/m2/}
}
依赖关系{
classpath(org.springframework.boot:spring-boot-gradle-plugin:$ {springBootVersion})
classpathgradle.plugin.com.ewerk.gradle.plugins :querydsl-plugin:1.0.7

}

套用插件:'java'
套用插件:'idea'
套用插件: 'eclipse'
apply plugin:'spring-boot'
apply plugin:'jacoco'
apply plugin:'groovy'
apply plugin:com.ewerk.gradle.plugins .querydsl

jar {
baseName ='billing'
version ='0.0.1-SNA PSHOT'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

知识库{
mavenCentral()
jcenter()
maven {urlhttps://repo.spring.io/snapshot}
maven {urlhttps://repo.spring.io/milestone}
maven {urlhttps ://repo.spring.io/libs-snapshot}
maven {urlhttps://repo.spring.io/libs-snapshot}
maven {urlhttps:// plugins .gradle.org / m2 /}

}

依赖关系{
compile('org.springframework.boot:spring-boot-starter-data-jpa ')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
编译com.querydsl:querydsl-root:$ querydslVersion
编译com.querydsl:querydsl-jpa:$ querydslVersion
compilecom.querydsl:querydsl-apt:$ querydslVersion:jpa

编译'org.codehaus.groovy:groovy-all:2.4.1'
编译fileTree(dir: libs / qbo-sdk-2.5.0,包括:* .jar)

testcompile('org.springframework.boot:spring-boot-starter-test')
testcompile('org.spockframework:spock-core:1.0-groovy-2.4'){
exclude group:'org.codehaus.groovy',module:'groovy-all'
}

testcompile('org.spockframework:spock-spring:1.0-groovy-2.4'){
exclude group:'org.spockframework',module:'spock-core'
}
testCompile(junit:junit)

}

sourceSets {
main {
output.resourcesDir = output.classesDir
}
generated {
java {
srcDirs = ['src / main / generated']
}
}
}

querydsl {
library ='com.mysema.querydsl:querydsl-apt'
querydslDefault = true
}


测试{
reports.junitXml.destination = file('build / test-results / folder')
}

jacoco {
toolVersion =0.7.0.201403182114
}

jacocoTestReport {
group =报告
description =运行测试后生成Jacoco覆盖率报告。
}

配置{
querydslapt
}

任务包装器(类型:包装器){
gradleVersion ='2.3'
}

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


当我运行我的单元测试时,出现错误:

 引发:java.lang.ClassNotFoundException:com.company.billing.customer.QCustomer 

当我运行gradle clean build时,得到:
找不到com.mysema.querydsl:querydsl-apt :.


在以下位置搜索:
https://repo1.maven.org/maven2/com/mysema/querydsl/querydsl-apt//querydsl-apt- .pom
https://repo1.maven.org/maven2/com/mysema/querydsl/querydsl-apt//querydsl-apt-.jar
https://jcenter.bintray.com/com /mysema/querydsl/querydsl-apt//querydsl-apt-.pom
https://jcenter.bintray.com/com/mysema/querydsl/querydsl-apt//querydsl-apt-.jar
https://repo.spring.io/snapshot /com/mysema/querydsl/querydsl-apt//querydsl-apt-.pom
https://repo.spring.io/snapshot/com/mysema/querydsl/querydsl-apt//querydsl-apt-.jar
https://repo.spring.io/milestone/com/mysema/querydsl/querydsl-apt//querydsl -apt-.pom
https://repo.spring.io/milestone/com/mysema/querydsl/querydsl-apt//querydsl-apt-.jar
https://repo.spring.io/libs-snapshot/com/ mysema / querydsl / querydsl-apt // querydsl-apt-.pom
https://repo.spring.io/libs-snapshot/com/mysema/querydsl/querydsl-apt//querydsl-apt-.jar


我意识到QueryDsl在3和3之间做了一些包重构。 4,但它看起来像我的依赖不能被发现,即使他们在这里清楚: https://mvnrepository.com/artifact/com.querydsl/querydsl-jpa/4.1.3



至少,这是我目前的理论为什么我的构建失败。有没有人得到最新的spring,gradle和querydsl工作?



更新
我删除了ewerk插件并简化了我的build.gradle文件,以便现在一切正常。我正在更新以帮助任何可能需要此功能的人:

  buildscript {
ext {
springBootVersion = '1.4.0.BUILD-SNAPSHOT'
querydslVersion ='4.1.3'
}
知识库{
mavenCentral()
maven {urlhttps:// repo.spring.io/snapshot}
maven {urlhttps://repo.spring.io/milestone}
}
依赖关系{
classpath(org。 springframework.boot:spring-boot-gradle-plugin:$ {springBootVersion})
}
}

apply plugin:'java'
apply plugin:' ''b $ b apply plugin:'eclipse'
apply plugin:'spring-boot'
apply plugin:'jacoco'
apply plugin:'groovy'

jar {
baseName ='billing'
version ='0.0.1 -SNAPSHOT'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

存储库{
mavenCentral()
jcenter()
maven {urlhttps://repo.spring.io/snapshot}
maven {urlhttps://repo.spring.io/milestone}
maven {urlhttps:// repo .spring.io / libs-snapshot}
maven {urlhttps://repo.spring.io/libs-snapshot}
maven {urlhttps://plugins.gradle.org / m2 /}
}

依赖关系{
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile( 'org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
compilecom.querydsl:querydsl- root:$ querydslVersion
compilecom.querydsl:querydsl-jpa:$ querydslVersion
compilecom.querydsl:querydsl-apt:$ querydslVersion:jpa

编译'org.codehaus.groovy:groovy-all:2.4.1'
编译fileTree(dir:libs / qbo-sdk-2.5.0,包括:* .jar)

testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.spockframework:spock -core:1.0-groovy-2.4'){
exclude group:'org.codehaus.groovy',module:'groovy-all'
}

testCompile('org .spockframework:spock-spring:1.0-groovy-2.4'){
exclude group:'org.spockframework',module:'spock-core'
}
testCompile(junit:junit )
}

test {
reports.junitXml.destination = file('build / test-results / folder')
}

jacoco {
toolVersion =0.7.0.201403182114
}

jacocoTestReport {
group =报告
description =生成Jacoco覆盖率报告运行测试后。


任务包装(类型:包装){
gradleVersion ='2.3'
}

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


解决方案

您是否在Gradle输出中看到了您的QClasses?从你的错误看来,它已经通过了应该产生它们的点。 我认为问题在于你没有配置 JPAAnnotationProcessor 。通过将jpa附加到你的querydsl-apt依赖项,这在gradle中是方便的。在Maven中,您手动应用插件 。 p>

我在与querydsl相关的build.gradle中有下面的内容。

  idea {
module {
sourceDirs + = file('generated /')
generatedSourceDirs + = file('generated /')
}
}
[...]
编译com.querydsl:querydsl-root:$ querydslVersion
compilecom.querydsl:querydsl -jpa:$ querydslVersion
compilecom.querydsl:querydsl -apt:$ querydslVersion:jpa

IDEA只是自动配置生成的源代码目录,以便in-IDE构建正常工作。



编辑:


$ b $ < JPAAnnotationProcessor 输出如下所示。

 注意:运行JPAAnnotationProcessor 
注意:序列化Supertypes
注意:生成com.myclass.example.QMappedSuperClass for [com.myclass.example.MappedSuperClass]
注意:序列化实体类型
注意:为[com.myclass.example.MyClass]生成com.myclass.example.QMyClass

编辑:



我对ewerk插件并不熟悉,所以我看着。它似乎正在尝试为您激活JPAAnnotationProcessor。您可能需要根据文档此处设置JPA标志为它默认为false。



请参阅有关依赖性问题的评论主题。


I have a Spring-boot 1.4 project in IntelliJ 15 using gradle 2.3 and QueryDSL 4.1.3 that won't build because my entities are not being built into Q classes by Querydsl. I have the following:

 buildscript {
    ext {
        springBootVersion = '1.4.0.BUILD-SNAPSHOT'
        querydslVersion = '4.1.3'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
        maven {url "https://plugins.gradle.org/m2/"}
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath "gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:1.0.7"
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'groovy'
apply plugin: "com.ewerk.gradle.plugins.querydsl"

jar {
    baseName = 'billing'
    version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
    maven { url "https://repo.spring.io/libs-snapshot" }
    maven { url "https://repo.spring.io/libs-snapshot"}
    maven {url "https://plugins.gradle.org/m2/"}

}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile "com.querydsl:querydsl-root:$querydslVersion"
    compile "com.querydsl:querydsl-jpa:$querydslVersion"
    compile "com.querydsl:querydsl-apt:$querydslVersion:jpa"

    compile 'org.codehaus.groovy:groovy-all:2.4.1'
    compile fileTree(dir: "libs/qbo-sdk-2.5.0", include: "*.jar")

    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
        exclude group: 'org.codehaus.groovy', module: 'groovy-all'
    }

    testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') {
        exclude group: 'org.spockframework', module: 'spock-core'
    }
    testCompile("junit:junit")

}

sourceSets {
    main {
        output.resourcesDir = output.classesDir
    }
    generated {
        java {
            srcDirs = ['src/main/generated']
        }
    }
}

querydsl {
    library = 'com.mysema.querydsl:querydsl-apt'
    querydslDefault = true
}


test {
    reports.junitXml.destination = file('build/test-results/folder')
}

jacoco {
    toolVersion = "0.7.0.201403182114"
}

jacocoTestReport {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
}

configurations {
    querydslapt
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

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

when I run my unit tests I get the error:

Caused by: java.lang.ClassNotFoundException: com.company.billing.customer.QCustomer

And when I run "gradle clean build" I get: Could not find com.mysema.querydsl:querydsl-apt:.

Searched in the following locations: https://repo1.maven.org/maven2/com/mysema/querydsl/querydsl-apt//querydsl-apt-.pom https://repo1.maven.org/maven2/com/mysema/querydsl/querydsl-apt//querydsl-apt-.jar https://jcenter.bintray.com/com/mysema/querydsl/querydsl-apt//querydsl-apt-.pom https://jcenter.bintray.com/com/mysema/querydsl/querydsl-apt//querydsl-apt-.jar https://repo.spring.io/snapshot/com/mysema/querydsl/querydsl-apt//querydsl-apt-.pom https://repo.spring.io/snapshot/com/mysema/querydsl/querydsl-apt//querydsl-apt-.jar https://repo.spring.io/milestone/com/mysema/querydsl/querydsl-apt//querydsl-apt-.pom https://repo.spring.io/milestone/com/mysema/querydsl/querydsl-apt//querydsl-apt-.jar https://repo.spring.io/libs-snapshot/com/mysema/querydsl/querydsl-apt//querydsl-apt-.pom https://repo.spring.io/libs-snapshot/com/mysema/querydsl/querydsl-apt//querydsl-apt-.jar

I realize that QueryDsl did some package refactoring between 3 & 4, but it looks like my dependencies are unable to be found even though they are clearly here: https://mvnrepository.com/artifact/com.querydsl/querydsl-jpa/4.1.3

At least, that is my current theory on why my build fails. Has anyone gotten the latest spring, gradle, and querydsl to work?

Update: I removed the ewerk plugin and simplified my build.gradle file so everything builds properly now. I am updating to help anyone else who might need this:

buildscript {
    ext {
        springBootVersion = '1.4.0.BUILD-SNAPSHOT'
        querydslVersion = '4.1.3'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'groovy'

jar {
    baseName = 'billing'
    version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
    maven { url "https://repo.spring.io/libs-snapshot" }
    maven { url "https://repo.spring.io/libs-snapshot"}
    maven {url "https://plugins.gradle.org/m2/"}
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile "com.querydsl:querydsl-root:$querydslVersion"
    compile "com.querydsl:querydsl-jpa:$querydslVersion"
    compile "com.querydsl:querydsl-apt:$querydslVersion:jpa"

    compile 'org.codehaus.groovy:groovy-all:2.4.1'
    compile fileTree(dir: "libs/qbo-sdk-2.5.0", include: "*.jar")

    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
        exclude group: 'org.codehaus.groovy', module: 'groovy-all'
    }

    testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') {
        exclude group: 'org.spockframework', module: 'spock-core'
    }
    testCompile("junit:junit")
}

test {
    reports.junitXml.destination = file('build/test-results/folder')
}

jacoco {
    toolVersion = "0.7.0.201403182114"
}

jacocoTestReport {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

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

解决方案

Do you see your QClasses being generated in the Gradle output? From your error it looks like it's already passed the point where it should generate them.

I think the problem is you are not configuring the JPAAnnotationProcessor. This is done as a convenience in gradle by appending :jpa to your querydsl-apt dependency. In Maven, you apply the plugin manually.

I have the below in my build.gradle related to querydsl.

idea {
    module {
        sourceDirs += file('generated/')
        generatedSourceDirs += file('generated/')
    }
}
[...]
compile "com.querydsl:querydsl-root:$querydslVersion"
compile "com.querydsl:querydsl-jpa:$querydslVersion"
compile "com.querydsl:querydsl-apt:$querydslVersion:jpa

The idea block just auto-configures the generated source dir in IDEA, so that in-IDE builds work correctly.

EDIT:

The JPAAnnotationProcessor output looks like the below.

Note: Running JPAAnnotationProcessor
Note: Serializing Supertypes
Note: Generating com.myclass.example.QMappedSuperClass for [com.myclass.example.MappedSuperClass]
Note: Serializing Entity types
Note: Generating com.myclass.example.QMyClass for [com.myclass.example.MyClass]

EDIT:

I wasn't familiar with the ewerk plugin, so I looked. It appears that it is trying to activate the JPAAnnotationProcessor for you. You may need to set the JPA flag per the documentation here as it defaults to false.

See comment thread regarding dependency issues.

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

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