Use properties with your gradle project.

Most of us are used in the maven way of specifying properties by using the properties tag


    2.0.9.RELEASE

and then when it comes to a dependency it can be easily referenced as ${springdata.commons}.


	org.springframework.data
	spring-data-commons
	${springdata.commons}

This is a bit tricky when it comes to gradle. The way  to do so is by using the extra properties extension.

ext{
  springdataCommons = "2.0.9.RELEASE"
}
dependencies {
    compile "org.springframework.data:spring-data-commons:${springdataCommons}"
}

Be aware that in order for this to work you should use double quotes, since in groovy double-quoted String literals support String interpolation while single quoted don’t.

This might work for you but you might want to use the dot character, for example springdata.commons .

That’s not possible using the previous way due to confusing the springdata as a symbol.
A workaround is to use the set method from ext.

ext{
    set('springdata.commons', "2.0.9.RELEASE")
}

dependencies {
    compile "org.springframework.data:spring-data-commons:${property('springdata.commons')}"
}

Pay attention to the compile section since you are going to have the same problem there regarding your name, thus you need to use an expression.

The other way around is to use a gradle.properties file and add there your properties.

springdata.commons=2.0.9.RELEASE

You compile section will be just the same.

dependencies {
    compile "org.springframework.data:spring-data-commons:${property('springdata.commons')}"
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.