Dynamic properties and dependencies version

Hey, I use to have that in build.gradle :

springVersion='3.1.0.RELEASE'
aspectjVersion='1.6.12'
  dependencies{
    ajc 'org.aspectj:aspectjtools:'+aspectjVersion
    compile 'org.aspectj:aspectjrt:'+aspectjVersion
    compile "org.aspectj:aspectjweaver:"+aspectjVersion
      compile "org.springframework:spring-core:"+springVersion
    compile "org.springframework:spring-context:"+springVersion
    compile "org.springframework:spring-aop:"+springVersion
    compile "org.springframework:spring-aspects:"+springVersion
    compile "org.springframework:spring-tx:"+springVersion
    compile "org.springframework:spring-web:"+springVersion
}

Now, I have the message error

Deprecated dynamic property: "springVersion" on "root project 'Data'", value: "3.1.0.RELEASE".
Deprecated dynamic property: "aspectjVersion" on "root project 'Data'", value: "1.6.12".

I have read the version notes of Gradle and fully understand the reason. I know that there is several way to resolve this warning but I am not sure of what is the good way to do it. So, since I think it’s a common problematic, I would like to have the advice of an expert : What is the best practice? Since those variables are useful only in the “dependencies” section, it makes sense to declare them inside this block. Is it possible?

You can move them into the ‘dependencies’ block if you want to. In any case, you need to make them extra variables (‘ext.’ or ‘ext { … }’). Instead of concatenating strings, you can use string interpolation (e.g. ‘“org.springframework:spring-web:$springVersion”’).

Actually I have resolved it like that :

ext.deps = [
    springVersion:'3.1.0.RELEASE',
    aspectjVersion:'1.6.12'
]
dependencies{
    println deps.dump()
    ajc 'org.aspectj:aspectjtools:'+deps.aspectjVersion
    compile 'org.aspectj:aspectjrt:'+deps.aspectjVersion
    compile "org.aspectj:aspectjweaver:"+deps.aspectjVersion
      compile "org.springframework:spring-core:"+deps.springVersion
    compile "org.springframework:spring-context:"+deps.springVersion
    compile "org.springframework:spring-aop:"+deps.springVersion
    compile "org.springframework:spring-aspects:"+deps.springVersion
    ajInpath "org.springframework:spring-aspects:"+deps.springVersion
    compile "org.springframework:spring-tx:"+deps.springVersion
    compile "org.springframework:spring-web:"+deps.springVersion
    compile "org.springframework:spring-webmvc:"+deps.springVersion
}

So, there’s no simpler/better solution? Something like that :

dependencies{
    springVersion='3.1.0.RELEASE'
    aspectjVersion='1.6.12'
      compile 'org.aspectj:aspectjrt:'+aspectjVersion
    compile "org.aspectj:aspectjweaver:"+aspectjVersion
    compile "org.springframework:spring-core:"+springVersion
    compile "org.springframework:spring-context:"+springVersion
    compile "org.springframework:spring-aop:"+springVersion
    compile "org.springframework:spring-aspects:"+springVersion
    compile "org.springframework:spring-tx:"+springVersion
    compile "org.springframework:spring-web:"+springVersion
}

Dependencies is not an object like task where I can put some properties?

BTW: Is there any reason to use string interpolation over concatenation?

Dependencies is not an object like task where I can put some properties?

As I said, you can move your variables inside the ‘dependencies’ block. But in any case, they need to be extra variables. You don’t necessarily need the ‘deps’ map; you can just have ‘ext.springVersion’ and ‘ext.aspectjVersion’. Alternatively, you can use an ‘ext {}’ block.

String interpolation is more convenient and more readable than concatenation, especially if you have multiple expressions.

Hi,

I am working on a multi module grails plugin project. Whenever a plugin is dependant across other plugins, i created a version param as

pluginVersion=2.0

in the main parent plugin’s build.gradle and used spring interpolation and added that as

com.test.p1:$pluginVersion

in all the plugins . It works fine in jenkins.

But, when i open in GGTS/Eclipse, it does not know what is pluginVersion? Can you please suggest a good mechanism of handling multiple plugin versions in GGTS/ eclipse?

Thanks Smurf