PatTheGamer
PatTheGamer

Reputation: 491

Gradle Compilation Error with Kotlin DSL configuring Java Spec

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.

Upvotes: 5

Views: 1849

Answers (1)

JB Nizet
JB Nizet

Reputation: 692231

You can just use

configure<JavaPluginExtension> { ... }

Upvotes: 8

Related Questions