0

I am trying to create sbt multi independent project.

I want my project structure some thing like

My Scala and sbt version is 2.12.2 and 1.5.5 respectively.

sbt-multi-project-example/
    common/
      project
      src/
        main/
        test/
      target/
      build.sbt
    multi1/
      project
      src/
        main/
        test/
      target/
      build.sbt
    multi2/
      project
      src/
        main/
        test/
      target/
      build.sbt
    project/
      build.properties
      plugins.sbt
    build.sbt

so I referred some github repo:

https://github.com/pbassiner/sbt-multi-project-example (project build is success but i want build.sbt in each individual modules.)

how can I create above project structure and basic idea is common project contains common methods and class. multi1(Independent project) uses common methods and it has its own methods and classes.

multi2(Independent project) uses common methods and it has its own methods and classes.

what are the changes I need to change in all build.sbt in order to achieve above scenario.

Tim
  • 26,753
  • 2
  • 16
  • 29
dp808139
  • 122
  • 2
  • 12
  • 2
    Can you explain why you want a `build.sbt` in each project? – Tim Jun 14 '22 at 20:10
  • Because after that i want to create dependency of each module for example if anyone want to use only module 2 then just add dependency of module 2 in thair project – dp808139 Jun 14 '22 at 20:31
  • You can refer this see how they create each module and each module has its own pom.xml here we have build.sbt https://github.com/apache/spark/tree/master/core and https://github.com/apache/spark/tree/master/graphx – dp808139 Jun 14 '22 at 20:36
  • 2
    Maven need a pom in each module, SBT does not. But SBT will still publish independent artifacts for each module and actually will publish one POM per module. Unless you clarify, there's no reason to want one SBT file per module. – Gaël J Jun 14 '22 at 20:46
  • Ok you mean with only one SBT I can achive above scenario right? Then its ok I can go ahead without SBT file in each module. Thanks – dp808139 Jun 14 '22 at 21:08

1 Answers1

2

This is the basic structure. As mentioned in the comments this can create a separate publishable artefact for each project so no need for a separate build.sbt

lazy val all = (project in file("."))
  .aggregate(common, multi1, multi2)

lazy val common =
  project
    .in(file("common"))
    .settings(
      name := "common",
      version := "0.1",
      // other project settings
    )

lazy val multi1 =
  project
    .in(file("multi1"))
    .settings(
      name := "multi1",
      version := "0.1",
    )
    .dependsOn(common)

Tim
  • 26,753
  • 2
  • 16
  • 29