一尘不染

具有QueryDSL和Gradle的IntelliJ 15

spring-boot

我在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'
    }
    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/')
    }
}

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

Caused by: 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和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'
    }
    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/')
    }
}

阅读 412

收藏
2020-05-30

共1个答案

一尘不染

您是否在Gradle输出中看到生成的QClass?从您的错误看来,它已经过了应该生成它们的地步。

我认为问题是您没有配置JPAAnnotationProcessor。为方便起见,通过将:jpa附加到querydsl-
apt依赖项中来完成此操作。在Maven中,您可以手动应用插件。

我的build.gradle中有以下与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

idea块仅在IDEA中自动配置生成的源目录,以便in-IDE构建正常工作。

编辑:

JPAAnnotationProcessor输出看起来像下面。

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]

编辑:

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

请参阅有关依赖关系问题的注释线程。编辑:对于Gradle 4.6+,您可以使用annotationProcessor语法。

api "com.querydsl:querydsl-root:$querydslVersion"
api "com.querydsl:querydsl-jpa:$querydslVersion"
annotationProcessor "com.querydsl:querydsl-apt:$querydslVersion:jpa"
2020-05-30