简体   繁体   English

Kotlin DSL配置Java规范时发生Gradle编译错误

[英]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. 我正在尝试为Kotlin项目创建构建文件,该文件有时会包含Java源代码。 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. 过去,在多项目构建中使用基于Groovy的构建文件时,我可以sourceCompatibilitysubproject块中指定sourceCompatibility 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: 使用Kotlin DSL,我知道它必须在java块中才能使用Kotlin DSL进行配置,但是当我尝试从根build.gradle.kts文件中的subproject块执行此操作时,出现编译错误:

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. 我在要使用的gradle构建文件中包含了要点 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. 现在,如果我在子项目build.gradle.kts文件之一中指定java块,就可以使它工作,但是我希望将设置应用于所有子项目,而不仅仅是特定项目。

你可以用

configure<JavaPluginExtension> { ... }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM