Kotlin is pretty popular these days, and it would be nice to have Kotlin support in Query DSL, in addition to the Scala one. It could allow me to use Query DSL SQL for the use case I have detail on https://spring.io/blog/2016/03/20/a-geospatial-messenger-with-kotlin-spring-boot-and-postgresql.
+1
+1
+1
+1
+1
+1
So, I was looking a bit, and the reference is a good start, but because we are not the intended audience for that[1] we'll have to consult the language spec.
I unfortunately have to say that there is not much to work with here.
The language spec is not complete, which isn't that much of a problem, but since we'll integrate with the tooling we will want to depend on laid out infrastructure, not kapt 0.1-SNAPSHOT
.
It's of course a little overkill to require Java level of detail documentation, but a bit less TODO
s might go a long way.
We will however add support for Kotlin to Codegen, so if at one point there is more information about how to integrate nicely, we can add such an integration.
So with that in mind, I think we'll keep this issue open until that moment.
I will reach Kotlin team about the problems you raised and make you a feedback.
is there any news?
There are still some issues.
You can also join in the Kotlin Slack, @sdeleuze already forwarded the request and they heard our request.
Unfortunately, there is still not much movement on the spec.
+1
+1
+1
+1
+1
This is an upstream issue, please refrain from posting +1 comments.
You can use the new reactions to show your involvement in the issue.
N.B. it looks like they moved the specification documentation into the main kotlin repository.
https://github.com/JetBrains/kotlin/tree/master/spec-docs
+1
Note that with the current version of Kotlin it is now possible to generate the Q-classes with kapt.
A build.gradle has to contain the following parts:
...
dependencies {
kapt "com.querydsl:querydsl-apt:$querydsl_version:jpa"
kapt 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
...
compile "com.querydsl:querydsl-jpa:$querydsl_version"
}
kapt {
generateStubs = true
}
sourceSets {
main.java.srcDirs += [file("$buildDir/generated/source/kapt/main")]
}
You should also try the new kotlin-kapt
plugin provided with Kotlin 1.0.6
, see https://blog.jetbrains.com/kotlin/2016/12/kotlin-1-0-6-is-here/. Not a silver bullet yet but seems promising.
I'll look at it later, thanks for the link.
-------- Original message --------
From: Alex Zuzin notifications@github.com
Date: 21/07/2017 17:28 (GMT+01:00)
To: querydsl/querydsl querydsl@noreply.github.com
Cc: Ruben Dijkstra ruben_dijkstra123@hotmail.com, Comment comment@noreply.github.com
Subject: Re: [querydsl/querydsl] Kotlin support (#1828)
https://github.com/JetBrains/kotlin-examples/tree/master/gradle/kotlin-querydsl
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com/querydsl/querydsl/issues/1828#issuecomment-317032056, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AD6jagAjEl8-cQDPW8d_qYIKhi5fojZSks5sQMOhgaJpZM4H0pT1.
For your convenience, I just took it apart and rebuilt on latest Kotlin, Hibernate 5.1.8.Final and QueryDSL 3.7.4. Relevant bits of build.gradle
: https://gist.github.com/zvozin/f46cc9fe1dd00bb648808317e77bf8ca.
Any example on how to do it with maven. I tried to get it done, but failed miserably :(
The examples on this issue + some tweaking to be more up-to-date allowed me to make it work.
Here are the additions to my build.gradle
file to make it work.
buildscript {
// ...
ext {
queryDslVersion = '4.1.3'
}
}
// ...
apply plugin: 'idea'
apply plugin: 'kotlin-kapt'
dependencies {
compile "com.querydsl:querydsl-jpa:$queryDslVersion"
kapt "com.querydsl:querydsl-apt:$queryDslVersion:jpa"
}
idea {
module {
def kaptMain = file('build/generated/source/kapt/main')
sourceDirs += kaptMain
generatedSourceDirs += kaptMain
}
}
FWIW, building off @Adeynack -- here's what I did to get it working fine with command line & intellij
plugins {
// ...
id "org.jetbrains.kotlin.kapt" version "1.2.70"
}
// ...
dependencies {
compile "com.querydsl:querydsl-jpa:4.2.1"
kapt "com.querydsl:querydsl-apt:4.2.1:jpa"
}
I didn't need the additional idea
section
How to configure maven, my project can compile if the service layer does not create QModel, but can't compile when the service layer creates QModel
Doesn't work with Kotlin 1.3
Every time i'm trying to build the project i get:
Caused by: java.lang.UnsupportedOperationException: no descriptor for type constructor of TypeVariable(R)?
at org.jetbrains.kotlin.load.kotlin.TypeSignatureMappingKt.mapType(typeSignatureMapping.kt:89)
at org.jetbrains.kotlin.codegen.state.KotlinTypeMapper.mapType(KotlinTypeMapper.java:502)
at org.jetbrains.kotlin.codegen.state.KotlinTypeMapper.mapType(KotlinTypeMapper.java:456)
at org.jetbrains.kotlin.codegen.CodegenUtilKt.asmType(codegenUtil.kt:274)
at org.jetbrains.kotlin.codegen.CodegenUtilKt.asmType(codegenUtil.kt:277)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.expressionType(ExpressionCodegen.java:459)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.visitSafeQualifiedExpression(ExpressionCodegen.java:3159)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.visitSafeQualifiedExpression(ExpressionCodegen.java:108)
at org.jetbrains.kotlin.psi.KtSafeQualifiedExpression.accept(KtSafeQualifiedExpression.kt:23)
at org.jetbrains.kotlin.codegen.CodegenStatementVisitor.visitKtElement(CodegenStatementVisitor.java:31)
at org.jetbrains.kotlin.codegen.CodegenStatementVisitor.visitKtElement(CodegenStatementVisitor.java:22)
at org.jetbrains.kotlin.psi.KtVisitor.visitExpression(KtVisitor.java:182)
at org.jetbrains.kotlin.psi.KtVisitor.visitQualifiedExpression(KtVisitor.java:286)
at org.jetbrains.kotlin.psi.KtVisitor.visitSafeQualifiedExpression(KtVisitor.java:306)
at org.jetbrains.kotlin.psi.KtSafeQualifiedExpression.accept(KtSafeQualifiedExpression.kt:23)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:296)
... 103 more
upd:
false alarm. i was using the new type inference model
-XXLanguage:+NewInference
i removed it and all works now
@deviant-studio fyi -- my solution above is still working with kotlin 1.3
@deviant-studio fyi -- my solution above is still working with kotlin 1.3
@nhajratw I tried the following:
plugins {
// ...
kotlin("kapt") version "1.3.61"
}
dependencies {
// ...
implementation("com.querydsl:querydsl-jpa:4.2.2")
kapt("com.querydsl:querydsl-apt:4.2.2:jpa")
}
Unfortunately I get a ClassNotFoundException
where it says Did not find a query class ...QClass
. It seems that the classes are not generated.
Do you know a fix to this issue?
@soprater sorry, i'm no longer working on the project where i had implemented this. Last i knew, it was working still. If i recall, you have to run the kaptGenerateStubsKotlin
task in order to get the XXXQClass
files.
It is still working. Kotlin 1.3.61, Spring 2.2.5.RELEASE, querydsl 4.2.2. I have these:
implementation("com.querydsl:querydsl-apt")
implementation("com.querydsl:querydsl-jpa")
I've built a module to support emitting kotlin Qclasses. If there's interest I could upstream that.
Most helpful comment
This is an upstream issue, please refrain from posting +1 comments.
You can use the new reactions to show your involvement in the issue.
N.B. it looks like they moved the specification documentation into the main kotlin repository.
https://github.com/JetBrains/kotlin/tree/master/spec-docs