Kotlin QueryDsl not generating Q classes - kotlin

I'm using kts gradle with koltin. However when i try to add QueryDsl it's not genetation Q classes from my JPA entities.
My build.gradle.kts looks like:
plugins {
id("org.springframework.boot") version "2.3.1.RELEASE"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
kotlin("jvm") version "1.3.72"
kotlin("plugin.spring") version "1.3.72"
kotlin("plugin.jpa") version "1.3.72"
kotlin("kapt") version "1.4.0"
kotlin("plugin.allopen") version "1.4.10"
}
dependencies {
// some spring boot dependencies here...
implementation("com.querydsl:querydsl-jpa:4.2.1")
kapt("com.querydsl:querydsl-apt:4.2.1:general")
}
kapt {
annotationProcessor("org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor")
}
I suggest it should build Q classes to build/generated/source/kapt/main. Any ideas why it's not working?
Also tried to annotate my entity with #QueryEntity annotation. Not working as well

Issue fixed by adding next configuration
// quert dsl
implementation("com.querydsl:querydsl-jpa:4.2.1")
kapt("com.querydsl:querydsl-apt:4.2.2:jpa")
annotationProcessor(group = "com.querydsl", name = "querydsl-apt", classifier = "jpa")
Also i removed
annotationProcessor("org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor")

Related

Why Kotlin 1.6.x uses kotlinx-coroutines 1.5.2 by default

I use Kotlin 1.6.20 in my Gradle project and It uses dependency kotlinx-coroutines 1.5.2 by default.
build.gradle.kts
plugins {
...
kotlin("jvm") version "1.6.20"
}
dependencies {
...
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm")
}
But latest version is 1.6.1.
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1")
Stability reason?

Specify kotlin version in buildSrc kotlin convention plugin

I am developing a Kotlin project with multiple subprojects as explained here
Building Kotlin Applications with libraries Sample (gradle.org)
Is it correct to specify the kotlin version as as shown below?
file: buildSrc/build.gradle.kts
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:<kotlin-version>")
}
Also, is it possible to move this kotlin version to a central location for declaring project-wide dependency version (for example gradle.properties or buildSrc/**/Dependencies.kt or versions catalog)? None of the approaches mentioned seems to be supported in buildSrc/build.gradle.kts.
There are many approaches to specify the kotlin version (or versions of any dependency) at a centralized location in a Gradle Multimodule Project.
gradle.properties
buildSrc/**/Dependency.kt
versions catalog
However, if you are defining a Kotlin Convention Plugin in buildSrc, the kotlin version is not available in buildSrc/build.gradle.kts using any of the methods mentioned above so as to pick the right kotlin-gradle-plugin.
For a workaround solution, use the following.
# file:<root>/gradle.properties
kotlinVersion=1.5.31
// file:<root>/buildSrc/build.gradle.kts
import java.io.*
import java.util.*
// read gradle.properties programmatically
val props = Properties()
FileInputStream(file("../gradle.properties")).use {
props.load(it)
}
plugins {
`kotlin-dsl`
}
repositories {
gradlePluginPortal()
}
dependencies {
val kotlinVersion = props.getProperty("kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
}
In all other <root>/**/<subproject>/build.gradle.kts files access the kotlinVersion like
val kotlinVersion = project.properties["kotlinVersion"]
In settings.gradle.kts, access the kotlinVersion like
val kotlinVersion:String by settings
If anyone from the Gradle team reading this, please provide an API to access gradle.properties consistently across any of the build script files.
in app gradle
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
and project gradle
ext.kotlin_version = "1.6.0"
I have solved this issue by specifying kotlinVersion in gradle.properties file as below.
kotlinVersion=1.6.10
Keep gradle.properties file at outermost project level.
You can access kotlinVersion in any submodules and project as
//top level declaration
val kotlinVersion by extra(project.property("kotlinVersion"))
//usage in dependency block
"org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
To verify whether you are able to read it, you can specify following
println(project.property("kotlinVersion"))
This should print kotlin version as
> Configure project :
1.6.10
build.gradle.kts file
val kotlinVersion by extra(project.property("kotlinVersion"))
println("${kotlinVersion}")
group = "com.company"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()
mavenLocal()
maven { url = uri("https://repo.spring.io/milestone") }
maven { url = uri("https://repo.spring.io/snapshot") }
gradlePluginPortal()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
}
gradle.properties file
kotlin.code.style=official
#kotlin.parallel.tasks.in.project=true
#kapt.incremental.apt=true
org.gradle.parallel=true
org.gradle.caching=false
org.gradle.daemon=true
org.gradle.jvmargs=-Dfile.encoding=UTF-8
kotlinVersion=1.6.10
Ref:
project_properties
extra_properties

Kotlin + Gradle for JVM New Module Error in IntelliJ

My project is composed of Kotlin/JVM + Gradle
I'm trying to add a module
After creating the module it gives me a single files:
|--main-project
|----new-module
|------build.gradle.kts
|--<other-main-project-files>
module gradle:
plugins {
kotlin("jvm") version "1.4.32"
}
group = "com.example"
version = "0.0.1"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
}
It gives me an error Unresolved reference implementation and I can't create kotlin/java files
I have no issue if I use java instead of kotlin/jvm
I fixed the problem after going through Gradle logs
kotlin("jvm") version "1.4.32"
should be changed to
kotlin("jvm")

How to force downgrade plugin version in in gradle?

So, I have kotlin plugin in my project set to latest stable release 1.3.72 but i have a dependency in which the plugin is defined as id 'org.jetbrains.kotlin.jvm' version 1.+ so it fetches 1.4-M1 which is actually not resolvable and I'm getting the following error:
Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4-M1.
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
This is how i defined version of it in my build.gradle file:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
id 'org.jetbrains.dokka' version '0.10.1'
}
...
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
...
}
Since the org.jetbrains.kotlin:kotlin-stdlib-jdk8 doesn't have 1.4-M1 release gradle could not resolve it. Is there any way to force downgrade the version of this?
I finally found the answer myself, I strictly defined version of org.jetbrains.kotlin:kotlin-stdlib-jdk8 and forced the ktor-dependency for using the defined version:
ext {
ktor_version='1.3.0'
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") {
version {
strictly "1.3.72"
}
because "1.4-M1 is not released"
}
implementation("io.ktor:ktor-server-core:$ktor_version") { force=true }
}

How to ignore explicitly importing classes like gradle kotlin script when writing custom kotlin-dsl

In the gradle's kotlin build script, we don't need explicitly import classes or functions like plugins, repositories or dependencies in build script build.gradle.kts.
plugins {
val kotlinVersion = "1.3.10"
val springBootVersion = "2.1.0.RELEASE"
val detektVersion = "1.0.0-RC10"
id("org.springframework.boot") version springBootVersion
id("org.jetbrains.kotlin.jvm") version kotlinVersion
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
id("io.spring.dependency-management") version "1.0.6.RELEASE"
id("io.gitlab.arturbosch.detekt") version detektVersion
}
repositories {
mavenLocal()
mavenCentral()
maven(url = uri("https://dl.bintray.com/s1m0nw1/KtsRunner"))
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-script-runtime")
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable")
implementation("org.jetbrains.kotlin:kotlin-script-util")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("cn.pilipa:pilipa-spring-boot-starter-logging:2.0.10")
implementation("de.swirtz:ktsRunner:0.0.5")
testImplementation("org.springframework.boot:spring-boot-starter-test"){
exclude(module = "junit")
}
testImplementation("io.projectreactor:reactor-test")
testImplementation("org.springframework.cloud:spring-cloud-stream-test-support")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testRuntime("org.junit.jupiter:junit-jupiter-engine")
testCompile("io.kotlintest:kotlintest-runner-junit5:${kotlinTestVersion}")
testCompile("io.kotlintest:kotlintest-extensions-spring:${kotlinTestVersion}")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:${detektVersion}")
}
How to implement this similar feature in the custom kotlin-dsl script to implicitly import classes in kotlin-dsl script?
Gradle defines a list of implicit imports that has no mechanism for extending this list. This is the same as for build.gradle and Groovy versions as it is for the Kotlin versions.
See also: Automatic imports in Gradle plugin
Which still holds true as of today. There is a TODO remaining in the Kotlin Gradle Script source code (master branch as-of Nov 22, 2018) related to this:
// TODO: let this be contributed by :plugins