Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Gradle生成Querydsl类时出现问题_Java_Gradle_Intellij Idea_Querydsl - Fatal编程技术网

Java 使用Gradle生成Querydsl类时出现问题

Java 使用Gradle生成Querydsl类时出现问题,java,gradle,intellij-idea,querydsl,Java,Gradle,Intellij Idea,Querydsl,我想使用querydsl生成“Q”类。我所面临的问题由错误描述: > Task :compileJava FAILED Attempt to recreate a file for type com.my.dinner.rest.database.entity.QIngredientAmount Attempt to recreate a file for type com.my.dinner.rest.database.entity.QUser Attempt to recreate

我想使用querydsl生成“Q”类。我所面临的问题由错误描述:

> Task :compileJava FAILED 
Attempt to recreate a file for type com.my.dinner.rest.database.entity.QIngredientAmount
Attempt to recreate a file for type com.my.dinner.rest.database.entity.QUser
Attempt to recreate a file for type com.my.dinner.rest.database.entity.QRating
Attempt to recreate a file for type com.my.dinner.rest.database.entity.QIngredient
Attempt to recreate a file for type com.my.dinner.rest.database.entity.QRecipe
error: Attempt to recreate a file for type
com.my.dinner.rest.database.entity.QIngredientAmount
error: Attempt to recreate a file for type com.my.dinner.rest.database.entity.QUser
error: Attempt to recreate a file for type com.my.dinner.rest.database.entity.QRating
error: Attempt to recreate a file for type com.my.dinner.rest.database.entity.QIngredient
error: Attempt to recreate a file for type com.my.dinner.rest.database.entity.QRecipe
5 errors
文件被生成,但构建失败,我想类被生成多次,但我不知道如何修复它。 我使用的技巧如下所述:

但这在我的情况下不起作用

我已经尝试了在Google、Github中找到的每一个build.gradle配置,但没有任何帮助

我的build.gradle文件:

plugins {
    id 'groovy'
    id 'java'
    id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
    id 'io.franzbecker.gradle-lombok' version '1.8'
}

sourceCompatibility = '11'
group 'com.my.dinner.rest'
version '1.0-SNAPSHOT'

def springBootVersion = '2.3.1.RELEASE'
def springFrameworkVersion = '5.2.7.RELEASE'
def lombokVersion = '1.18.12'
def querydslVersion = '4.3.1'

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.4', ext: 'pom'

    // Spring
    compile group: 'org.springframework', name: 'spring', version: springFrameworkVersion, ext: 'pom'
    compile group: 'org.springframework', name: 'spring-webmvc', version: springFrameworkVersion

    compile group: 'org.springframework.boot', name: 'spring-boot', version: springBootVersion
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: springBootVersion
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion

    // Hibernate
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.17.Final'
    compile group: 'org.hibernate.validator', name: 'hibernate-validator', version: '6.1.5.Final'

    // Querydsl
    implementation group: 'com.querydsl', name: 'querydsl-jpa', version: querydslVersion
    implementation group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion
    implementation group: 'com.querydsl', name: 'querydsl-core', version: querydslVersion

    // Others
    compile group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
    compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
    compile group: 'com.typesafe', name: 'config', version: '1.4.0'
    compile group: 'org.modelmapper', name: 'modelmapper', version: '2.3.8'

    annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBootVersion
    annotationProcessor group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
    annotationProcessor group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
    annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    annotationProcessor group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion
    annotationProcessor group: 'com.querydsl', 'name': 'querydsl-apt', version: querydslVersion, classifier: 'jpa'

    testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion
    testCompile group: 'junit', name: 'junit', version: '4.13'
    testCompile group: 'com.h2database', name: 'h2', version: '1.4.200'
}

def querydslSrcDir = "$buildDir/generated"

sourceSets {
    main {
        java {
            srcDirs = ["$projectDir/src/main/java", querydslSrcDir]
        }
    }
}

compileQuerydsl {
    options.annotationProcessorPath = configurations.querydsl
}

querydsl {
    library = "com.querydsl:querydsl-apt"
    jpa = true
    querydslSourcesDir = querydslSrcDir
}

configurations {
    querydsl.extendsFrom compileClasspath

    compileOnly {
        extendsFrom annotationProcessor
    }
}

clean.doLast {
    file(querydslSrcDir).deleteDir()
}
plugins {
    id 'groovy'
    id 'java'
}

sourceCompatibility = '11'
group 'com.my.dinner.rest'
version '1.0-SNAPSHOT'

def springBootVersion = '2.3.1.RELEASE'
def springFrameworkVersion = '5.2.7.RELEASE'
def lombokVersion = '1.18.12'
def querydslVersion = '4.3.1'

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.4', ext: 'pom'

    // Spring
    compile group: 'org.springframework', name: 'spring', version: springFrameworkVersion, ext: 'pom'
    compile group: 'org.springframework', name: 'spring-webmvc', version: springFrameworkVersion

    compile group: 'org.springframework.boot', name: 'spring-boot', version: springBootVersion
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBootVersion
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: springBootVersion
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion

    // Hibernate
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.17.Final'
    compile group: 'org.hibernate.validator', name: 'hibernate-validator', version: '6.1.5.Final'

    // Querydsl
    implementation group: 'com.querydsl', name: 'querydsl-jpa', version: querydslVersion
    implementation group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion
    implementation group: 'com.querydsl', name: 'querydsl-core', version: querydslVersion

    // Others
    compile group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
    compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
    compile group: 'com.typesafe', name: 'config', version: '1.4.0'
    compile group: 'org.modelmapper', name: 'modelmapper', version: '2.3.8'

    annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBootVersion
    annotationProcessor group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
    annotationProcessor group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
    annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    annotationProcessor group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion
    annotationProcessor group: 'com.querydsl', 'name': 'querydsl-apt', version: querydslVersion, classifier: 'jpa'

    testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion
    testCompile group: 'junit', name: 'junit', version: '4.13'
    testCompile group: 'com.h2database', name: 'h2', version: '1.4.200'
}
渐变版本:6.5


Intellij版本:2020.1

,所以我随机更改build.gradle文件来解决它

我删除了不必要的插件和依赖项下面的一整节,它在中生成了所有类:

build/generated/annotationProcessor/java/main

我更新的build.gradle文件:

plugins {
    id 'groovy'
    id 'java'
    id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
    id 'io.franzbecker.gradle-lombok' version '1.8'
}

sourceCompatibility = '11'
group 'com.my.dinner.rest'
version '1.0-SNAPSHOT'

def springBootVersion = '2.3.1.RELEASE'
def springFrameworkVersion = '5.2.7.RELEASE'
def lombokVersion = '1.18.12'
def querydslVersion = '4.3.1'

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.4', ext: 'pom'

    // Spring
    compile group: 'org.springframework', name: 'spring', version: springFrameworkVersion, ext: 'pom'
    compile group: 'org.springframework', name: 'spring-webmvc', version: springFrameworkVersion

    compile group: 'org.springframework.boot', name: 'spring-boot', version: springBootVersion
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: springBootVersion
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion

    // Hibernate
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.17.Final'
    compile group: 'org.hibernate.validator', name: 'hibernate-validator', version: '6.1.5.Final'

    // Querydsl
    implementation group: 'com.querydsl', name: 'querydsl-jpa', version: querydslVersion
    implementation group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion
    implementation group: 'com.querydsl', name: 'querydsl-core', version: querydslVersion

    // Others
    compile group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
    compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
    compile group: 'com.typesafe', name: 'config', version: '1.4.0'
    compile group: 'org.modelmapper', name: 'modelmapper', version: '2.3.8'

    annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBootVersion
    annotationProcessor group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
    annotationProcessor group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
    annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    annotationProcessor group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion
    annotationProcessor group: 'com.querydsl', 'name': 'querydsl-apt', version: querydslVersion, classifier: 'jpa'

    testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion
    testCompile group: 'junit', name: 'junit', version: '4.13'
    testCompile group: 'com.h2database', name: 'h2', version: '1.4.200'
}

def querydslSrcDir = "$buildDir/generated"

sourceSets {
    main {
        java {
            srcDirs = ["$projectDir/src/main/java", querydslSrcDir]
        }
    }
}

compileQuerydsl {
    options.annotationProcessorPath = configurations.querydsl
}

querydsl {
    library = "com.querydsl:querydsl-apt"
    jpa = true
    querydslSourcesDir = querydslSrcDir
}

configurations {
    querydsl.extendsFrom compileClasspath

    compileOnly {
        extendsFrom annotationProcessor
    }
}

clean.doLast {
    file(querydslSrcDir).deleteDir()
}
plugins {
    id 'groovy'
    id 'java'
}

sourceCompatibility = '11'
group 'com.my.dinner.rest'
version '1.0-SNAPSHOT'

def springBootVersion = '2.3.1.RELEASE'
def springFrameworkVersion = '5.2.7.RELEASE'
def lombokVersion = '1.18.12'
def querydslVersion = '4.3.1'

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.4', ext: 'pom'

    // Spring
    compile group: 'org.springframework', name: 'spring', version: springFrameworkVersion, ext: 'pom'
    compile group: 'org.springframework', name: 'spring-webmvc', version: springFrameworkVersion

    compile group: 'org.springframework.boot', name: 'spring-boot', version: springBootVersion
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBootVersion
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: springBootVersion
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion

    // Hibernate
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.17.Final'
    compile group: 'org.hibernate.validator', name: 'hibernate-validator', version: '6.1.5.Final'

    // Querydsl
    implementation group: 'com.querydsl', name: 'querydsl-jpa', version: querydslVersion
    implementation group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion
    implementation group: 'com.querydsl', name: 'querydsl-core', version: querydslVersion

    // Others
    compile group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
    compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
    compile group: 'com.typesafe', name: 'config', version: '1.4.0'
    compile group: 'org.modelmapper', name: 'modelmapper', version: '2.3.8'

    annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBootVersion
    annotationProcessor group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
    annotationProcessor group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
    annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    annotationProcessor group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion
    annotationProcessor group: 'com.querydsl', 'name': 'querydsl-apt', version: querydslVersion, classifier: 'jpa'

    testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion
    testCompile group: 'junit', name: 'junit', version: '4.13'
    testCompile group: 'com.h2database', name: 'h2', version: '1.4.200'
}
版本:

Java:11.0.7 格拉德尔:6.5 Intellij:2020.1.1 Ubuntu:20.04 LTS
因此,我认为我之前研究过的关于这个问题的所有问题都与较旧的gradle版本有关,并且有许多变通方法不需要在我的gradle版本中应用。

compileOnly{ExtendFrom annotationProcessor}为什么?当您在annotationProcessor配置中有库时,querydsl插件可能与较新版本的Gradle运行处理器本身的方式不兼容?请检查生成类的位置。我怀疑当生成类和普通类编译的输出路径混乱时,可能会发生错误。例如,querydsl.ExtendFrom compileClasspath-不确定,但它可能会更改输出路径。Gradle用于生成的类,您可以根据自己的配置进行更改。