Skip to content

How to both use Querydsl and lombok with gradle?  #2444

@LilithXing

Description

@LilithXing

java 11
gradle 5.4
idea 2018.3

This is my gradle config

plugins {
    id 'java'
    id 'idea'
    id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
    id "org.springframework.boot" version "2.1.4.RELEASE"
    id "io.franzbecker.gradle-lombok" version "3.0.0"
    id 'io.spring.dependency-management' version "1.0.7.RELEASE"
}

group 'cn.org.cczr'
version '1.0-SNAPSHOT'
//apply plugin: 'io.spring.dependency-management'

sourceCompatibility = 11
targetCompatibility = 11

sourceSets {
    main {
        java {
            srcDir "$buildDir/generated/source/main"
        }
    }
}

compileQuerydsl {
    options.annotationProcessorPath = configurations.querydsl
}

querydsl {
    jpa = true
    querydslSourcesDir = "$buildDir/generated/source/main"
}

project.afterEvaluate {
    project.tasks.compileQuerydsl.options.compilerArgs = [
            "-proc:only",
            "-processor", project.querydsl.processors() +
                    ',lombok.launch.AnnotationProcessorHider$AnnotationProcessor'
    ]
}

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
}

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-web')
    implementation('org.springframework.boot:spring-boot-starter-data-jpa')

    implementation "com.querydsl:querydsl-jpa" // querydsl
    implementation "com.querydsl:querydsl-apt"  // querydsl
    implementation("org.projectlombok:lombok:1.18.6")

    annotationProcessor(
            "com.querydsl:querydsl-apt:4.1.4:jpa",
            "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final",
            "javax.annotation:javax.annotation-api",
            "org.projectlombok:lombok:1.18.6"
    )

    testImplementation('org.springframework.boot:spring-boot-starter-test')
    testImplementation group: 'junit', name: 'junit', version: '4.12'
    testImplementation("org.projectlombok:lombok:1.18.6")
    testAnnotationProcessor("org.projectlombok:lombok:1.18.6")
}

then when i use gradle build

it report error
Execution failed for task ':compileQuerydsl'.
Annotation processor 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor' not found

if i delete the lombok dependcies ,the querydsl even not work normal ,
it report error
can't find find symbol and the package don't exist

so how can i both use Querydsl and lombok with gradle?

and i think use querydsl with gradle is so difficulty,you must config so many option,
just like

sourceSets {
    main {
        java {
            srcDir "$buildDir/generated/source/main"
        }
    }
}

compileQuerydsl {
    options.annotationProcessorPath = configurations.querydsl
}

querydsl {
    jpa = true
    querydslSourcesDir = "$buildDir/generated/source/main"
}

project.afterEvaluate {
    project.tasks.compileQuerydsl.options.compilerArgs = [
            "-proc:only",
            "-processor", project.querydsl.processors() +
                    ',lombok.launch.AnnotationProcessorHider$AnnotationProcessor'
    ]
}

compare with maven config,it's too troublesome.
Is there a easier way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions