Querydsl - Intellij and code generation

1,216 views
Skip to first unread message

Henrique Luis Schmidt

unread,
Mar 6, 2018, 12:45:48 PM3/6/18
to Querydsl

I have a Spring Boot Gradle project using Spring Data MongoDB.

In order to generate the query type classes, I have to run the gradle build task.


Is there a way for creating the query type classes when saving the file in IntelliJ? I have already enabled annotation processing in the project.

I would like to have a behavior like the lombok plugin, where it is not needed to build the project to see the changes.


Below is my build.gradle file:

buildscript {
    ext {
        springBootVersion = '2.0.0.RELEASE'
    }
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("io.franzbecker:gradle-lombok:1.11")
        classpath("gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:1.0.9")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "io.franzbecker.gradle-lombok"
apply plugin: "com.ewerk.gradle.plugins.querydsl"

group = 'com.henrique'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-mongodb')
    compile("com.querydsl:querydsl-mongodb:4.1.4")
    compileOnly("com.querydsl:querydsl-apt:4.1.4")
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

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

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

Here is my domain entity:

@Data
@Builder
@Document
public class Customer {

@Id
private String id;

private String firstName;
private String lastName;

private String zipCode;

}

And here is the query type generated:

@Generated("com.querydsl.codegen.EntitySerializer")
public class QCustomer extends EntityPathBase<Customer> {

    private static final long serialVersionUID = -1386833698L;

    public static final QCustomer customer = new QCustomer("customer");

    public final StringPath firstName = createString("firstName");

    public final StringPath id = createString("id");

    public final StringPath lastName = createString("lastName");

    public final StringPath zipCode = createString("zipCode");

    public QCustomer(String variable) {
        super(Customer.class, forVariable(variable));
    }

    public QCustomer(Path<? extends Customer> path) {
        super(path.getType(), path.getMetadata());
    }

    public QCustomer(PathMetadata metadata) {
        super(Customer.class, metadata);
    }

}
Reply all
Reply to author
Forward
0 new messages