Advice on (multi-) project layout design

Hello. I am currently in the process of migrating several projects to gradle.
I am struggling to find the correct way in which my projects should depend on each other.
I am using Eclipse 4.12 and Gradle 5.5.

The structure is as follows (naming each project and its dependent projects):

  1. The ‘main’ project
  2. A specialized project which builds upon 1.
  3. Another specialzed project which depends on 1.
  4. A project which combines and extends 2 & 3

There are two main factors that make this more complicated:

  1. The projects should be able to act like ‘stand alone’ projects unless they are being used by a project that depends on them.
    For example, project 1 should be fully functional when used on its own, but should act as a ‘subproject’ when used by project 2.
  2. Projects 1 & 2 are being versioned. It should be optional whether projects 3&4 depend on versions (artefacts served by a maven repo) of 1&2 respectively,
    or whether they sould depend on the “live version” of 1&2, via some sort of include-Method.

Currently I am going about it as follows:
Project 3 defines a property ‘BUILD_DEPENDENCY’ which decides whether the project should be build locally or based on their artefacts.
Depending on that property project 3 has an optional include of project 1. (includeBuild)
Project 4 has an includeBuild on project 3. Based on ‘BUILD_DEPENDENCY’ it may or may not includeBuild project 2.
Project 2 has an includeBuild on project 1, BUILD_DEPENDENCY is not being considered here.
Now, in case the BUILD_DEPENDENCY is set to building locally I run into the first error:
Project 1 is now being imported twice. From project 4’s perspective, it now includes 2 & 3 which in turn both include project 1, which is illegal.
I solved this by making the include of project 1 in project 2 optional, depending on whether gradle.parent is null or not.
That is presuming that when a gradle.parent is present, project 2 is being used in a composite build based on project 4.
Project 4 is happy now, which is nice.
Unfortunately project 2 is no longer working as a standalone project.
That is because whenever project 2 is being configured, 4 is being configured as well.
Presumably that is because 2 has a reference to 4 inside org.eclipse.buildship.core.prefs.
As a consequence gradle.parent is again != null which prevents 2 from including 1, thus it cannot build.
To prevent that from happening I am now letting all projects clean up the org.eclipse.buildship.core.prefs of their childrens so that the children can later be used as standalone projects. I am doing so inside eclipse.autoBuildTasks (other hooks were too early and thus had no effect).

This does not feel like a good solution.
Unfortunately I couldn’t come up with anything better as of now.
I have omitted some side issues and things I’ve tried to keep this post somewhat resonably sized.

Thanks for any advice you could give.