Get this error when building a Spring project:

FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':compile'.
> Could not resolve${springVersion}.
  Required by:
   > Illegal character in path at index 81:${springVersion}/spring-security-core-${springVersion}.pom

It looks like Gradle directly add ${springVersion} to path string, it should first replace the variable in the path string. The varialbe springVersion is defined at the top of gradle build script


This is how the spring security dependency is declared:

    compile '${springVersion}'
    compile '${springVersion}'
    compile '${springVersion}'
    compile '${springVersion}'

But another format has no problem

    compile "org.springframework:spring-orm:$springVersion"

This is called string interpolation in Groovy. According to Groovy documentation, only double quoted string support string interpolation, here is the example:

hello = "hello"
println '${hello} world'
println "${hello} world"
println "$hello world"
// output
//${hello} world
//hello world
//hello world

This example shows that the single quoted string can not do string interpolation. But sometime the gradle build script which contains the wrong dependency string can still build successfully, the reason is there are JAR caches in local, maybe downloaded by another project's successful build. Gradle would not actually use the string in such case, so the wrong string would not cause problem.