My company is currently switching from Ant to Gradle for its Java projects, but I am stuck with a nice clean setup. Let's say I work for a company that builds websites for clients which generally use the same root libraries (core project), but have some specific code, which is put in the sub-project. Per client, we build a new sub-project, that depends on the core project. Number of clients will increase in the future.

Currently we have three projects:

* A core project. This should run individually, as we want to be able to do the unit testing seperately for this.
* Two sub-projects that depend on the core project, but have some own projects that are specific to the project.

I was sucessful in converting the whole ant build into a gradle build for the core project. My idea is to have all functionality and project structure in the core, and only the extra for what is actually needed in the sub-projects.

Here is a short sample of our folder structure:

```
-- core
    - build.gradle
    - settings.gradle
    -- repository (our external jars used)
    -- Implementation
      -- source_code
        -- all the core project folders
      -- Projects
        -- Client A
          - build.gradle
          - settings.gradle
          -- more project specific folders
        -- Client B
          - build.gradle
          - settings.gradle
          -- more project specific folders

```

I use the $rootDir variable a lot. A fraction of the core's settings.gradle looks as such:

```
project(':CoreProjectA').projectDir = new File(rootDir, 'Implementation/Source_code/Core/coreA')
project(':CoreProjectB').projectDir = new File(rootDir, 'Implementation/Source_code/Core/CoreB')

```

But with many more. Also, in the core build.gradle, I refer to our repository as such:

```
repositories {
   //All sub-projects will now refer to the same 'libs' directory
    flatDir {
        dirs "$rootDir/repository/lib/jaxb"
        //many more dirs here
    }
}

```

Now this all works great when I do a gradle build from the core project.
I was planning to put the next piece of code in every client's subproject build.gradle:

```
apply from: '../../../build.gradle'

```

When I run a gradle build from Client A folder, my rootDir obviously has changed, and now, all my paths cannot be found anywhere.

Is there any way to set this up in a nice clean way? So that every future sub project added can always use the same structure? Or will I have to give each sub-project its own build.gradle and settings.gradle entirely?

I know the last option could work, but it is a lot of overhead, and just doesn't seem nice and clean to me at all..

Thanks in advance!