在gradle文件中指定多个依赖项

问题描述 投票:1回答:2

基于以下参考:https://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-dependency-management/

我相信我可以在依赖配置下指定多个依赖项,如下所示:

Multiple Dependencies under one dependency configuration

但是,当我尝试运行gradle build时,我看到以下错误。 enter image description here

这不是在gradle文件中提供多个依赖项的正确方法吗?

D:\TestGradle>gradle build
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\TestGradle\build-ProblemTemplate.gradle' line: 116
* What went wrong:
Could not compile build file 'D:\TestGradle\build-ProblemTemplate.gradle'.
> startup failed:
  build file 'D:\TestGradle\build-ProblemTemplate.gradle': 116: expecting ')', found ',' @ line 116, column 68.
     toolVersions.mockitoVersion}'],
                                   ^
  1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
D:\TestGradle>

还尝试删除testCompile配置中的[],如下面的JakubWójcik的回答中所述。但仍然得到同样的错误。

更新令人惊讶的是,在依赖配置名称为我工作后删除换行符。它与[]括号一起工作正常。仍然不知道为什么这很重要,但到目前为止用我的发现更新了帖子。

Working gradle dependency file.

gradle build.gradle
2个回答
2
投票

您可以尝试使用每个参数的配置指定依赖项。我认为这是最常见和最常用的方式。

dependecies {
    compile 'dep1'
    compile 'dep2'
}

或者如果你真的想传入一个以逗号分隔的args来编译闭包。

dependecies {
    compile (
        'dep1',
        'dep2'
    )
}

PS。当使用qazxsw poi时,你需要使用G String qazxsw poi(双引号)。

PPS。您可以将vararg或数组传递给它并不重要的配置。


对于新线路

Gradle使用groovy作为其脚本,这实际上不是故意的错误,因为$variables"可能被解释为编译器的单独块。请参阅()

它在一天结束时全部到Groovy解析器:)


-1
投票

当testCompile子句具有多个依赖项时,请尝试删除{}括号。另外,请注意您在118行中有一个额外的Context-sensitive_grammar

© www.soinside.com 2019 - 2024. All rights reserved.