makozaki
makozaki

Reputation: 4366

Load common properties in build.gradle doesn't work for buildscript

I have multiple projects which share common properties. I want to manage common dependencies in one place so I decided to use this approach (from Edit section).

//properties.gradle
ext {
    pluginVersion = "x.x.x"
}
//build.gradle
apply from: '/path/to/properties.gradle'

buildscript {
    dependencies {
        classpath "some.group:some-plugin:${pluginVersion}"
    }
}
...

This results with following error:

Could not get unknown property 'pluginVersion'

What should I do to load properties from properties.gradle file? What am I doing wrong? Is buildscript section somehow different than other sections?

I'll just add that before extracting common properties I kept them all in gradle.properties file and they worked fine.

Upvotes: 1

Views: 344

Answers (1)

tap12_admk
tap12_admk

Reputation: 26

Looks like buildscript section runs before apply ...

Try moving apply inside buildscript like that:

//build.gradle
buildscript {
    apply from: '/path/to/properties.gradle'
    dependencies {
        classpath "some.group:some-plugin:${pluginVersion}"
    }
}
...

Upvotes: 1

Related Questions