gradle - 我怎样才能让 gradle 5 预编译脚本插件在包中时开始工作
问题描述
我想通过使用gradle 5.3.1 引入的预编译脚本插件build.gradle.kts
功能来模块化我的文件。
当我直接有我的简单hello-world.gradle.kts
文件时它工作正常buildSrc/src/main/kotlin
tasks.register("hello-world") { println("hello world") }
并将其包含在我的 main 的 plugins 部分中build.gradle.kts
:
plugins {
`hello-world`
}
我现在可以使用gradle hello-world
并查看预期的输出。
但是,当我将相同的脚本放入buildSrc/src/main/kotlin/custom/hello-world-custom.gradle.kts
(添加package custom
到脚本中)时,它会失败,尽管文档指出:
同样,只要 src/main/kotlin/my/java-library-convention.gradle.kts 有一个 my.java-library-convention 的包声明,它就会产生一个插件 ID 为 my.java-library-convention。
主要build.gradle.kts
:
plugins {
`custom.hello-world-custom`
}
但相反,我收到一个错误:
Script compilation error:
Line 3: `custom.hello-world-custom`
^ Unresolved reference: `custom.hello-world-custom`
任何想法如何解决这一问题?
更新:为了重现这一点,我创建了一个包含不同“hello world”任务的小型仓库。
解决方案
从文档中不太清楚,但我找到了解决方案:
该包必须在反引号之外定义:
plugins {
`hello-world`
custom.`hello-world-custom`
}
推荐阅读
- java - 在运行时设置 application.properties
- java - Android Http 请求 POST JSON
- git - 如何显示包含父母信息的所有提交列表?
- javascript - 窗口提交方法内的Javascript停止工作
- pandas - Pandas:组合具有不同值的行
- python - 从导入的脚本函数返回 for 循环中的变量
- google-api - YouTube 数据 API 不再从 search.list 返回活跃的直播流
- sql - 计算每个 ID 显示的特定值的数量
- javascript - 使用javascript将数组作为猫鼬模式中的值
- excel - 是编写这段代码的更好更优雅/更有效的方式