【问题标题】:How to generate QueryDSL mongoDB and lombok in (modern) gradle如何在(现代)gradle 中生成 QueryDSL mongoDB 和 lombok
【发布时间】:2022-10-09 17:48:18
【问题描述】:

让 QueryDSL 和 lombok 一起工作并不容易,尤其是因为 querydsl 的 gradle 文档充其量是缺乏的。

我想避免使用仍然依赖于compile 配置的 autdated 插件,或者在破坏其他系统的额外任务(如 intellij idea 构建)中进行黑客攻击。

经历所有不起作用的事情会花费我一段时间,所以我将这个问题和答案留给其他人(可能还有我未来的自己)。

【问题讨论】:

    标签: gradle lombok querydsl


    【解决方案1】:
    plugins {
        id 'java'
        id 'org.springframework.boot'
        id 'io.spring.dependency-management'
    }
    
    repositories {
        mavenCentral()
    }
    
    sourceCompatibility = '17'
    
    ext{
        springBootVersion = "2.7.4"
    }
    
    dependencies {
        implementation(platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}"))
        implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
        implementation 'org.springframework.boot:spring-boot-starter-web'
        testImplementation "org.springframework.boot:spring-boot-starter-test"
        testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'
    }
    
    ext {
        queryDslVersion = "5.0.0"
    }
    
    configurations {
        compileOnly {
            extendsFrom annotationProcessor
        }
    }
    
    dependencies {
        //required to use dependency management to find the right versions. Alternatively specify the version in the dependency directly
        annotationProcessor(platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}"))
        compileOnly "org.projectlombok:lombok"
        annotationProcessor "org.projectlombok:lombok"
        testCompileOnly "org.projectlombok:lombok"
        testAnnotationProcessor "org.projectlombok:lombok"
    
        //querydsl
        implementation("com.querydsl:querydsl-core:${queryDslVersion}")
        annotationProcessor("com.querydsl:querydsl-apt:${queryDslVersion}:general")
        //I'm lazily using the full starter here to automatically include other annotation dependencies like validation. You could specify them separately/specifically
        annotationProcessor('org.springframework.boot:spring-boot-starter-data-mongodb')
    }
    
    //adding both annotation processors directly on the compiler options make them work together nicely.
    compileJava {
        options.compilerArgs += [
                "-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor,org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor'
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-30
      • 2019-05-31
      • 2017-03-16
      • 2019-03-22
      • 2021-05-08
      • 2019-12-14
      • 2017-01-18
      • 2017-11-15
      相关资源
      最近更新 更多