What's the build.gradle file resolution hierarchy?

(Bryan Stopp) #1

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:


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


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 ?



(Peter Niederwieser) #2

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.

(Bryan Stopp) #3


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?

(Peter Niederwieser) #4

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.