How can I import one Gradle script into another?

There is a new feature in 0.9. You can use apply from: 'other.gradle' command.

Read my question about same thing at: Is there a way to split/factor out common parts of Gradle build


The answer to the question turned out to be in the Plugins system, where you can add the desired functionality in a set of plugins which can be groovy files located in the directory buildSrc/src/main/groovy. Plugins can also be bundled as a Jar though I haven't tried this.

Details here: Custom Plugins


Well, it is hard to tell what serves you best without actually seeing your build file.

I could assume that stetting up your environment as multi-project build should provide you the abstraction you are looking for.

In your project root build.gradle you define all your domain specific stuff as well as the things that apply to all your subprojects:

repositories {
    add(new org.apache.ivy.plugins.resolver.FileSystemResolver()) {
        name = 'destRepo'
        addIvyPattern( file( project.properties['repo.dest.dir']).absolutePath + '/[organisation]/[module]/ivys/ivy(-[revision]).xml')
        addArtifactPattern( file( project.properties['repo.dest.dir']).absolutePath + '/[organisation]/[module]/[type]s/[artifact](-[revision]).[ext]')
        descriptor = 'optional'
        checkmodified = true
    }
    ...
}
...
subprojects {
    sourceCompatibility = 1.5
    targetCompatibility = 1.5
    group = 'my.group'
    version = '1.0'
    uploadArchives {
        uploadDescriptor = true
        repositories {
            add rootProject.repositories.destRepo
        }
    }
    apply{ type my.group.gradle.api.plugins.MyPlugin }
    ...
}

dependsOnChildren()

The project root directory might also contain a gradle.properties file where you define properties used by your projects:

buildDirName=staging
repo.dest.dir=/var/repo
...

Then in an additional file from your project root named settings.gradle you actually point to your subprojects:

include 'my-first-component',
        'my-second-component'
...
project(':my-first-component').projectDir = new File(rootDir, 'path/to/first/component')
project(':my-second-component').projectDir = new File(rootDir, 'path/to/second/component')
...

Each sub-project directory contains a build.gradle file containing the sub-project specific stuff only.

No matter if you invoke gradle from your project root or sub-project directory, gradle will automatically consider all your definitions done in the various files.

Also note that no compile task will be executed for your project root as long as you don't load any plugin beyond the default plugin at the root level.