java - 使用 Kotlin DSL 配置 Java 规范的 Gradle 编译错误
问题描述
我正在尝试为有时包含 java 源的 Kotlin 项目创建构建文件。过去在多项目构建中使用基于 Groovy 的构建文件时,我可以毫无问题地sourceCompatibility
在subproject
块中指定。使用 Kotlin DSL,我知道它必须在java
块中才能使用 Kotlin DSL 进行配置,但是当我尝试从subproject
根build.gradle.kts
文件中的块中执行此操作时,出现编译错误:
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 构建文件中包含了一个要点。现在,如果我在其中一个子项目文件中指定 java 块,我可以让它工作build.gradle.kts
,但我希望将设置应用于所有子项目,而不仅仅是特定项目。
解决方案
你可以使用
configure<JavaPluginExtension> { ... }
推荐阅读
- python - 如何使用python从特定的推特用户那里获取推文
- elasticsearch - 使用弹性心跳监控进程
- javascript - 具有 React-Datepicker 问题的 Formik 字段
- python - 为什么我得到 TypeError: 'int' object is not iterable
- autosys - Autosys - 如何设置文件观察器作业以查找以日期命名的文件,即使服务器日期更改为第二天
- javascript - 如何确定初始化为数组的游戏板网格是否包含获胜条件
- kubernetes - kubernetes 配置部署删除现有文件
- javascript - jquery draggable:可拖动在页面滚动时保持静止
- javascript - 制作长度为 n 的随机字符串,仅由 0 和 1 组成
- sql-server - 在同一查询中选择普通列和格式化为 XML 的列