Specify Dependency Versions as Properties

In before “1.0-milestone-9” times I had a very simple “versions.gradle” file where I defined versions as:

scalaVersion = '2.9.1'
scalaTest = '1.6.1'
  junitVersion = '4.+'
mockitoVersion = '1.9.0-rc1'

and referenced them as:

testCompile (
        ... ...
        [ group: 'org.scalatest',
     name: 'scalatest_2.9.1',
       version: scalaTest ],
        [ group: 'org.mockito',
       name: 'mockito-all',
           version: mockitoVersion ],
        [ group: 'junit',
             name: 'junit',
                 version: junitVersion ]
    )
      // libraries needed to run the scala tools
    scalaTools (
        [group: 'org.scala-lang',
name: 'scala-compiler',
version: scalaVersion ],
        [group: 'org.scala-lang',
name: 'scala-library',
 version: scalaVersion ]
    )

Now with “1.0-milestone-9” we have this thing => http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html

Which is quite confusing, as it does not reveal the “whys”, but only specifies the “hows”, which are hard to connect to simple real world things such as “specify a version property for an artifact”.

=> 1. What is the current approach to do that? Should it be done as:

project.version.scala = "2.9.1"

and then used as “project.version.scala” in deps. Or should it be done in any other way?

=> 2. Is there a way to go back to a simple " ‘scalalVersion = 2.9.1’ => ‘version: scalaVersion’ " usage? If not, why?

=> 3. What is the (usage) purpose of introducing ExtraPropertiesExtension?

Thank you.

Hello, Have a look at the forum post Luke wrote a couple of days ago about deprecating “dynamic properties” at http://forums.gradle.org/gradle/topics/6caj90zrfqr0l

The changes in your build file are not that complicated I guess, you just have to refactor

scalaVersion = '2.9.1'
scalaTest = '1.6.1'
junitVersion = '4.+'
mockitoVersion = '1.9.0-rc1'

to

ext{
   scalaVersion = '2.9.1'
   scalaTest = '1.6.1'
   junitVersion = '4.+'
   mockitoVersion = '1.9.0-rc1'
}

That should do the trick.

regards, René

@Rene,

ext{}

did it. thank you. (although of course it became a lot less intuitive)

… and a lot safer. People used to experience lots of troubles due to (unnoticed) typos in their build scripts. Extra properties go a long way towards solving this problem.