在另一个模块中使用自定义gradle插件模块 [英] Use Custom gradle plugin module in another module
问题描述
我正在开发一个自定义插件,希望以后可以将其部署到存储库,因此我为它创建了一个独立模块。
I am developing a custom plugin that I want to be able to deploy to a repository at a later stage so I've created a stand alone module for it.
在我执行任何正式的TDD之前,我想手动进行某些探索性测试,因此,我创建了一个使用给定插件的演示模块。
Before I do any formal TDD on it, I wanna do certain exploratory tests manually so, I've created a demo module that uses the given plugin in.
到目前为止,我发现这样做的方法是将插件部署到本地存储库中,然后将其导入其他模块中。但这很繁琐,而且很容易忘记部署它。
The only way I've found so far to do this was to deploy the plugin into a local repository and then import it on the other module. But this is very tedious and it's quite easy to forget to deploy it.
我想知道是否有办法更直接地做到这一点。
I was wondering if there is a way to do this more straight forward.
推荐答案
更新(2020-09-07):
可以使用 includeBuild( plugin / module)
将模块添加到项目的类路径中,以便可以应用插件。需要注意的是,如果您想将其应用到 settings.gradle [.kts]
上,则无法使用,正如我在此线程。
Update(2020-09-07):
It's possible to use includeBuild("plugin/module")
to add a module into the classpath of the project so the plugin can be applied. With one caveat, it doesn't work yet if you want to apply it on settings.gradle[.kts]
as I found out on this thread.
我发现的最佳解决方案是将插件模块的文件夹作为buildSrc模块(用于本地脚本)的一部分包含在其源代码集中像这样:
The best solution I've found was to include the folders of the plugin module as part of the buildSrc module (used for local scripting) within it's source sets like:
sourceSets {
main {
groovy.srcDirs += "../custom-plugin/src/main/groovy"
resources.srcDirs += "../custom-plugin/src/main/resources"
}
}
这将使您像在远程存储库中一样使用插件但不必每次都部署它。下一个单元测试:)
This will let you use the plugin as if it was in the remote repository but without having to deploy it every time. Next unit tests :)
这篇关于在另一个模块中使用自定义gradle插件模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!