What's the build.gradle file resolution hierarchy?

This has probably been answered, but no search criteria i input gives me what i’m looking for.

I’m using the demo gradle project:

https://gist.github.com/bstopp/6116d46b2eb488a4e77e

But in our organization we use Artifactory, which provides you a build.gradle script to support configuring the build for dependency resolution and push.

https://gist.github.com/bstopp/18e8038fde96a7a9c67d

I don’t want to have to repeat the Artifactory configuration for every project. So i tried to put the build.gradle file in my ~/.gradle directory, but it didn’t resolve to our artifactory repository.

I tried to name the file init.gradle, which then locates the file. However it doesn’t resolve the properties, as it’s before build configurations are applied.

Is there a place, similar to Maven’s setting.xml, where global configuration options can be applied, without having to be repeated ?

Thanks,

-B

You can use ‘~/.gradle/init.gradle’, but ‘init.gradle’ isn’t quite the same as ‘build.gradle’. For details see the Gradle User Guide and Gradle Build Language Reference. You may also find some samples in the full Gradle distribution.

Peter,

I used init.gradle. However, when I executed the project, as i mentioned, it could not resolve the username/password for the buildscript repository’s configuration.

Any other thoughts?

You can’t just rename the file, you have to adapt it with ‘gradle.rootProject {}’, ‘gradle.allprojects { … }’, etc. I’m not sure if this will work to define the root project’s ‘buildscript’ section, but it might.