Define extension properties from settings.gradle


(steve) #1

I have a Gradle-built project which builds the JPA APIs. Part of the artifact name is the JPA version (we use the artifact version for our build number). I have that set up in settings.xml as:

rootProject.name = 'hibernate-jpa-2.1-api'

However, there are a few references to the JPA version in build.gradle as well. So in the interest of defining things in one place I realy wanted to do something like:

rootProject.ext.jpaVersion = "2.1"
rootProject.name = 'hibernate-jpa-2.1-api'

And then be able to reference rootProject.ext.jpaVersion in build.gradle as well. However, Gradle did not like this.

Is there a strategy for accomplishing what I want?


(Peter Niederwieser) #2

I think you mean ‘settings.gradle’. :slight_smile:

‘settings.gradle’ and ‘build.gradle’ use different representations for a project (‘ProjectDescriptor’ and ‘Project’, respectively). What they do have in common is the ‘gradle’ property/object. Hence you could use ‘gradle.ext.jpaVersion’. (Note: Only use ‘ext’ when setting the property.)


(steve) #3

Ah, thanks! gradle.ext.jpaVersion and gradle.jpaVersion worked great