'Specifying multiple dependencies in gradle file
Based on references below: https://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-dependency-management/
I believe I can specify multiple dependencies under a dependency configuration like below:
However, when I try to run gradle build, I see the following errors.
Is this not the right way to provide multiple dependencies in a gradle file?
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>
Also tried removing the [] in the testCompile configuration as mentioned in answer from Jakub Wójcik below. But still get the same error.
Update Surprisingly, removing the line break after dependency configuration name worked for me. It worked fine with or with out [] brackets. Still don't know why this matters, but updating the thread with my findings so far.
Solution 1:[1]
You can try specifying the dependencies with the configuration for each one of them. I think this is most common and used way.
dependencies {
compile 'dep1'
compile 'dep2'
}
or if you really want to just pass in a comma-separated args to compile closure.
dependencies {
compile (
'dep1',
'dep2'
)
}
PS. When using $variables
you need to use the GString "
(double quotes).
PPS. You can pass a vararg or an array to the configuration it doesn't really matter.
For the new lines
Gradle uses groovy for its scripts and this is not a bug its intentional actually, because ()
or {}
may be interpreted as a separate block for the compiler. Refer to Context-sensitive_grammar
Its all to Groovy parser at the end of the day :)
Solution 2:[2]
Try removing the []
brackets, when having multiple dependencies for a testCompile clause. Also, note that you have an extra "
in the line 118.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ben Cox |
Solution 2 | Jakub Wójcik |