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 org.springframework.security:spring-security-core:${springVersion}.
  Required by:
      :SpringSecurityExample:1.0
   > Illegal character in path at index 81: http://repo1.maven.org/maven2/org/springframework/security/spring-security-core/${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

 
ext.springVersion='3.2.1.RELEASE'
 

This is how the spring security dependency is declared:

 
    compile 'org.springframework.security:spring-security-core:${springVersion}'
    compile 'org.springframework.security:spring-security-web:${springVersion}'
    compile 'org.springframework.security:spring-security-config:${springVersion}'
    compile 'org.springframework.security:spring-security-taglibs:${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.