如何使用gradle添加项目依赖项? [英] How to add Project Dependency using gradle?
问题描述
我正面临以下问题.我需要构建多项目,但是当我尝试添加依赖项时,出现以下错误.
I am facing the following problem. I need to build the multi-project, but when I try to add the dependency I got the following error.
根项目的设置.gradle:
include 'DbServices','HelloWeb'
Root Project的build.gradle:
apply plugin: 'java'
project(':HelloWeb') {
dependencies {
compile (':DbServices')
}
}
DbServices的build.gradle:
apply plugin: 'java'
HelloWeb的build.gradle:
apply plugin: 'java'
但是,当与Root Project上的gradle任务同步时,出现以下错误:
However, then I am getting the following error when synchronize with the gradle tasks on Root Project:
执行命令:任务"
Executing command: "tasks"
失败:构建失败,并出现异常.
FAILURE: Build failed with an exception.
-
其中: 构建文件'D:\ MyDeployment \ RootProject \ build.gradle'行:21
Where: Build file 'D:\MyDeployment\RootProject\build.gradle' line: 21
出了什么问题: 评估根项目"RootProject"时出现问题.
What went wrong: A problem occurred evaluating root project 'RootProject'.
在org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@3b3e3b3e上找不到参数[:DbServices]的方法compile().
Could not find method compile() for arguments [:DbServices] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@3b3e3b3e.
尝试: 使用--info或--debug选项运行,以获取更多日志输出.
Try: Run with --info or --debug option to get more log output.
例外是: org.gradle.api.GradleScriptException:评估根项目'RootProject'时出现问题.
Exception is: org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'RootProject'.
推荐答案
文档使用以下语法:
dependencies {
compile project(':DbServices')
}
这篇关于如何使用gradle添加项目依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!