Define extension properties from settings.gradle

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?

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.)

1 Like

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