簡體   English   中英

Kotlin DSL配置Java規范時發生Gradle編譯錯誤

[英]Gradle Compilation Error with Kotlin DSL configuring Java Spec

我正在嘗試為Kotlin項目創建構建文件,該文件有時會包含Java源代碼。 過去,在多項目構建中使用基於Groovy的構建文件時,我可以sourceCompatibilitysubproject塊中指定sourceCompatibility 使用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

我在要使用的gradle構建文件中包含了要點 現在,如果我在子項目build.gradle.kts文件之一中指定java塊,就可以使它工作,但是我希望將設置應用於所有子項目,而不僅僅是特定項目。

你可以用

configure<JavaPluginExtension> { ... }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM