def getRootGradle() {
    def currentGradle = gradle
    while (currentGradle.parent) {
        currentGradle = currentGradle.parent
    }
    return currentGradle
}

def findHookIncludedBuild() {
    def rootGradle = getRootGradle()
    def hookProject = rootGradle.getIncludedBuilds()
            .find({ build -> build.name == 'hook' })
    return hookProject
}

def findGlobalConfig() {
    def hookProject = findHookIncludedBuild()
    if (hookProject) {
        def path = hookProject.projectDir.parent + '/globalConfig.gradle'
        if (file(path).exists()) {
            return path
        }
    }
}

def globalConfigPath = findGlobalConfig()
if (globalConfigPath) {
    apply from: globalConfigPath
}