When building Java or Groovy using Gradle, it's possible to define source encoding like this:
compileJava {
options.encoding = 'UTF-8'
}
compileTestJava {
options.encoding = 'UTF-8'
}
compileGroovy {
groovyOptions.encoding = 'UTF-8'
}
compileTestGroovy {
groovyOptions.encoding = 'UTF-8'
}
However, similar approach with Kotlin doesn't work:
compileKotlin {
kotlinOptions.jvmTarget = '1.8'
kotlinOptions.encoding = 'UTF-8'
}
It fails with the error:
* What went wrong:
A problem occurred evaluating root project 'backend'.
> No such property: encoding for class: org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptionsImpl
I actually can't find any info about Kotlin compiler's encoding at all. Does it mean that there is no such option? What charset does it use then, UTF-8, system default (I hope not)?
If we want to set an explicit encoding for the Java compiler in Gradle we can use the options. encoding property. For example we could add the following line to our Gradle build file to change the encoding for the compileJava task: ?
Simply, it stands for 'Domain Specific Language'. IMO, in gradle context, DSL gives you a gradle specific way to form your build scripts. More precisely, it's a plugin-based build system that defines a way of setting up your build script using (mainly) building blocks defined in various plugins.
Go to Intellij Preferences -> Build, Execution, Deployment -> Kotlin Compiler. Update Language version and Api version to the one you wish.
Kotlin DSL brings the simplicity of the Kotlin language syntax and rich API set right into the script files on top of that code completion makes it perfect to work with Gradle script files. We will use this to manage our dependencies and project settings configurations more elegantly.
Kotlin source files are always UTF-8 by design. There is no way to specify any other encoding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With