Gradle 无法使用 fileTree 将依赖项注入到子项目中
也许我错过了 Gradle 工作方式的一些内容。我这里有一个父项目,它只包含配置,即构建它时不会构建任何工件,它只是管理和构建它的所有子项目。
现在子项目共享一些依赖项配置,所以我想我会在根项目的 build.gradle 中执行以下操作:
subprojects {
dependencies {
compile fileTree(dir: 'lib', includes: ['*.jar'])
}
}
但是,这不起作用,它会失败并显示一条相当晦涩的错误消息:
评估 root 时出现问题 项目“qype-android”原因:否 方法签名: org.gradle.api.internal.artifacts.dsl.dependency.DefaultDependencyHandler.compile() 适用于参数类型: (org.gradle.api.internal.file.DefaultConfigurableFileTree) 值:[文件集“lib”]可能 解决方案: module(java.lang.Object)
经过一些试验和错误,我可以通过将“java”插件应用到父项目来“修复”这个问题。
怎么会?我在 Gradle 文档中没有看到 fileTree
依赖项需要 Java 插件。即便如此,为什么我在注入配置的项目上需要它,而不是在正在配置的项目上(请注意,子项目都应用 Java 插件本身)?
这是否意味着,如果我有 N 个性质各异的不同子项目,并应用不同的插件,那么父项目也必须始终应用在某处使用的所有插件集?
Maybe I'm missing something about the way Gradle works. What I have here is a parent project, which only contains configuration, i.e. there won't be any artifact being built when building it, it merely manages and builds all its subprojects.
Now the subprojects share some dependency configuration, so I figured what I would do in the root project's build.gradle is:
subprojects {
dependencies {
compile fileTree(dir: 'lib', includes: ['*.jar'])
}
}
that, however, does not work, it fails with a rather obscure error message:
A problem occurred evaluating root
project 'qype-android' Cause: No
signature of method:
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile()
is applicable for argument types:
(org.gradle.api.internal.file.DefaultConfigurableFileTree)
values: [file set 'lib'] Possible
solutions: module(java.lang.Object)
after some trial and error, I could "fix" this issue by applying the 'java' plugin to the parent project.
How come? I don't see anywhere from the Gradle docs that a fileTree
dependency requires the Java plugin. Even so, why would I need it on the project that is injecting the configuration, as opposed to on the project that is being configured (note that the subprojects all apply the Java plugin themselves)?
Does this mean that if I have N different subprojects that are all of varying natures, and apply different plugins, that the parent projects must always apply the set of all plugins beings used somewhere to itself, too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不是需要“java”插件的
fileTree
。错误消息抱怨未定义的
compile
依赖项配置。 Java 插件为您定义了此配置,以便您可以向其添加依赖项(包括您的 fileTree)。It is not the
fileTree
that requires 'java' plugin.The error message is complaining about undefined
compile
dependency configuration. Java plugin defines this configuration for you, so that you can add dependencies (including your fileTree) to it.