How to inherit build from external parent

Hi - I’ve been reading through the docs and see lots about multi-module builds, but I don’t see an answer that quite fits the pattern we are trying to use.

We have a core framework team that has developed core code that multiple teams want to use.
project teams should be able to run all core tasks and tests, plus should be able to create their own

The core framework is published as a jar to artifactory,
project teams then extend it and add their own custom tests, resources and custom settings (e.g DB hosts, users, etc)

The primary purpose of this framework is as a TestFramework - it runs common BDD and unit tests that apply to all projects using common test resources, and then each project also defines their own custom BDD tests and test resources

CoreFrameworkProject

  • framework --> published to artifactory as coreframework.jar
    ----src/main [contains core code other projects will inherit from]
    ----src/test [contains test code other projects will run]
    ---- build.gradle --> contains code to publish jar to artifactory
  • othersubmodule --> published to artifactory as othersubmodule .jar
    ---- build.gradle --> contains code to publish jar to artifactory
    build.gradle --> defines dependencies, repos, plugins, sourceSets, and tasks
    settings --> includes othersubmodule and framework

OtherTeam1Project

  • src/main --> code that extends the framework
  • src/test --> can run tests for this project AND common tests from core
    build.gradle --> need to be able to:
    use same dependencies, sourcesets etc from core Framework [inherit config from core?]
    execute all tasks contained in framework
    PLUS add its own custom tasks

OtherTeam2Project

  • src/main --> code that extends the framework
  • src/test --> can run tests for this project AND common tests from core
    build.gradle --> need to be able to:
    use same dependencies, sourcesets etc from core Framework [inherit config from core?]
    execute all tasks contained in framework
    PLUS add its own custom tasks

etc…

CoreFrameworkProject, OtherTeam1Project, OtherTeam2Project are stored separately in their own git repos, so each is a root project. The core project doesn’t know anything about the other projects

We want to make common build scripts so we can share common settings and dont have to repeat build logic for every new project (otherwise that would be a maintenance nightmare, if you add something to the core project, we dont want to have to edit all the downstream projects

I have tried adding the coreFramework as a compiled dependency, and doing an “apply from” to load common settings, but I ran into issues where some scripts were loaded in the parent, and then we try and load again in the other projects, gradle complains that the task already exists.

Whats the right way to do this? any good examples out there?

  • I’m assuming we cant just add common build logic to an allproects section of the root as the CoreFrameworkProject’s settings file doesnt know anything about OtherTeam1Project etc,
  • Or is there some way for a new project to add itself as a subproject or to extend its build