thxwelchs
thxwelchs

Reputation: 15

How do I generate QClass in kotlin spring boot?

I want to use querydsl in kotlin spring boot environment. But I don't know how to set the kotlin gradle.

There is a lot of information on how to set up the groovy dsl, but the kotlin dsl setup is not detailed.

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("plugin.jpa") version "1.2.71"
    id("org.springframework.boot") version "2.1.5.RELEASE"
    id("io.spring.dependency-management") version "0.6.0.RELEASE"
    kotlin("jvm") version "1.2.71"
    kotlin("plugin.spring") version "1.2.71"

//    kotlin("kapt") version "1.3.31"
}


group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
    mavenCentral()
    maven { url = uri("https://plugins.gradle.org/m2/") }
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-jdbc")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    runtimeOnly("mysql:mysql-connector-java")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    compile("com.querydsl", "querydsl-jpa", "3.6.3")
    kapt("com.mysema.querydslquerydsl-apt:3.6.3:jpa") 
}


group = "com.acme"
tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}



Upvotes: 1

Views: 1437

Answers (1)

asm0dey
asm0dey

Reputation: 2931

This github repo has example with generating QueryDSL entities from kotlin sources in project with Spring Boot.

It's not trivial because by default querydsl generates classes from source code and parses Java, not Kotlin. Yet it's possible

Upvotes: 1

Related Questions