I'm attempting to create a build file for a Kotlin project that will sometimes include java sources. In the past with the Groovy based build files in a multi-project build, I could specify the sourceCompatibility
in the subproject
block with no issue. With the Kotlin DSL I know it must be in the java
block to configure with the Kotlin DSL, but when I attempt to do that from the subproject
block in my root build.gradle.kts
file I get a compilation error:
Script compilation errors:
Line 14: java {
^ Expression 'java' cannot be invoked as a function. The function 'invoke()' is not found
Line 14: java {
^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public val PluginDependenciesSpec.java: PluginDependencySpec defined in org.gradle.kotlin.dsl
Line 15: sourceCompatibility = JavaVersion.VERSION_1_8
^ Unresolved reference: sourceCompatibility
3 errors
I've included a gist to the gradle build file I'm using. Now I can get it working if I specify the java block in one of the subprojects build.gradle.kts
files, but I want the setting applied to all of the subprojects, not just specific projects.
Gradle's Kotlin DSL provides an alternative syntax to the traditional Groovy DSL with an enhanced editing experience in supported IDEs, with superior content assist, refactoring, documentation, and more.
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.
The Kotlin DSL provides built-in support for three destination types: Fragment , Activity , and NavGraph destinations, each of which has its own inline extension function available for building and configuring the destination.
You can just use
configure<JavaPluginExtension> { ... }
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