升级到Gradle 5后Querydsl注释处理器问题 [英] Querydsl Annotation Processor issue after upgrade to Gradle 5

查看:300
本文介绍了升级到Gradle 5后Querydsl注释处理器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gradle脚本,该脚本从Mongo带注释的实体生成querydsl类.到目前为止,它已经可以使用了,但是升级到Gradle 5之后,我遇到了一个问题:

I have a gradle script which generates querydsl classes from Mongo annotated entities. It was working so far, but after upgrade to Gradle 5 I have a problem with:

* What went wrong:
Execution failed for task ':myproject-common:compileQuerydsl'.
Annotation processor 'org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor' not found

请在下面找到我的gradle.build脚本.任何想法可能有什么问题吗?我了解到Gradle 5中发生了变化,即在编译过程中默认情况下不使用注释处理器,并且应该添加注解处理器声明,但是当我将其添加到依赖项时,会发生相同的错误.

Please find my gradle.build script below. Any ideas what could be wrong? I read that there was change in Gradle 5 that annotation processors are not used by default during compilation and annotationProcessor declaration should be added but when I add it to dependencies the same error occurs.

plugins {
    id 'org.springframework.boot' version '2.0.4.RELEASE'
    id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}
repositories {
    mavenCentral()
}
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
jar {
    enabled = true
    baseName = 'myproject-common'
    version =  '0.0.1-SNAPSHOT'
}
// do no package commons into fat jar
bootJar {
    enabled = false
}
querydsl {
    library = 'com.querydsl:querydsl-apt:4.1.4'
    querydslSourcesDir = 'src/main/querydsl'
    springDataMongo = true
}
sourceCompatibility = 11.0
targetCompatibility = 11.0
sourceSets {
    main {
        java {
            srcDirs = ['src/main/java', 'src/main/querydsl']
        }
    }
}
dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.data:spring-data-mongodb")
    compile("org.springframework.boot:spring-boot-starter-data-rest")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("com.fasterxml.jackson.datatype:jackson-datatype-    jsr310:2.8.6")
    compile("com.google.guava:guava:23.0")
    compile("commons-io:commons-io:2.5")
    compile("org.aspectj:aspectjweaver:1.8.9")
    compile("org.apache.commons:commons-lang3:3.5")
    compile("commons-collections:commons-collections:3.2.2")
    compile("org.javamoney:moneta:1.1")
    compile("com.fizzed:rocker-runtime:1.2.0")
    compile("com.querydsl:querydsl-core:4.1.4")
    compile("com.querydsl:querydsl-mongodb:4.1.4")
    compile("com.querydsl:querydsl-apt:4.1.4")
    compile("com.codepoetics:protonpack:1.15")

    testCompile("org.springframework.boot:spring-boot-starter-test")
    testCompile("org.assertj:assertj-core:3.7.0")
}

推荐答案

这是我在不使用其他插件的情况下对JPA的有效配置. Gradle 5.3,openjdk 11.0.2.

This is my working configuration for JPA without using additional plugins. Gradle 5.3, openjdk 11.0.2.

plugins {
    id 'java-library'
}

ext {
    springBootVersion = '2.2.0.M1'
    queryDslVersion = '4.2.1'
}

dependencies {
    api(
            "com.querydsl:querydsl-jpa:$queryDslVersion"
    )

    implementation(
            platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion"),
            'org.springframework.boot:spring-boot-starter-validation',
            'org.springframework.boot:spring-boot-starter-data-jpa',
            'org.liquibase:liquibase-core',
            'org.postgresql:postgresql'
    )

    annotationProcessor(
            platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion"),
            'jakarta.persistence:jakarta.persistence-api',
            'jakarta.annotation:jakarta.annotation-api',
            "com.querydsl:querydsl-apt:$queryDslVersion:jpa"

    )
}

请注意注释处理器.后缀为:jpa".可能这就是您所错过的.要为mongodb激活同一个,应添加:morphia"后缀.

Please pay attention to the annotation processor. It has suffix ":jpa". Probably this is what you missed. To activate the same one for mongodb you should add ":morphia" suffix.

请同时查看以下两个依赖项:

Please also look at these 2 dependencies:

'jakarta.persistence:jakarta.persistence-api'
'jakarta.annotation:jakarta.annotation-api'

这是解决此处所述问题的方法: https://discuss.gradle.org/t/annotationprocessor-querydsl -java-lang-noclassdeffounderror/27107 它们应该是注释处理器的可传递依赖项,但现在还不是.可能您也必须将一些mongo依赖项也包含到commentProcessor中. 生成的源位于\build\generated\sources\annotationProcessor\java\main

This is a workaround for the issue described here: https://discuss.gradle.org/t/annotationprocessor-querydsl-java-lang-noclassdeffounderror/27107 They should be transitive dependencies of the annotation processor, but they aren't yet. Probably you will have to include some mongo dependencies to annotationProcessor too. Generated sources are located in \build\generated\sources\annotationProcessor\java\main

这篇关于升级到Gradle 5后Querydsl注释处理器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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