Search code examples
gitsbtmulti-module

SBT multi project with distant parent


I'm working on a Scala project using SBT and as the codebase becomes too heavy and complex for one project / repo we are going to split it and push modules in a nexus for dependency retrieval.

Current layout looks like this:

project-stack/ # Unique git repo
├── build.sbt # root
├── connector1_module/
│   └── build.sbt
├── connector2_module/
│   └── build.sbt
└── jobs_module/
    └── build.sbt

However we have a lot of common information in the root build that we don't want to repeat and maintain across all projects and repositories (namely dependency versions, sbt plugins and configurations, ...).

New layout would look like this:

project-stack/ # Parent project repo
└── build.sbt # define all common properties

connector1_module/ # another git repo
└── build.sbt # inherit from project-stack

connector1_module/ # another git repo
└── build.sbt # inherit from project-stack

jobs_module/ # another git repo
└── build.sbt  # inherit from project-stack

I have a bit of experience on Maven and using it we would have done a parent POM with all properties and have the different projects inheriting it. Does SBT support a similar inheritance of parent information from a distant SBT project?

I know one solution would be to keep the monolithic structure and use git sub-modules but I'd like to avoid the complexity if possible.

Thanks

-- Edit:
I'm working with SBT version 1.1.6


Solution

  • sbt does not have similar approach as maven does with a distant parent. But in contrast to maven, sbt is very friendly in writing your own plugin that can rely on other plugins.

    You could create one single sbt plugin, ie sbt-my-company-name and embed into it what is in your root project now. It can contain common 3rd-party plugins and enable them in specific way. You could encode common library dependencies too.

    Check out how to create your own plugin with this tutorial.