Search code examples
scalasbt

sbt publish a package with varying dependencies


I have an sbt project which consists of 3 different layer:

  • base
  • impl (is a directory which contains many different implementation packages, and each package depends on base)
  • api (depends on an "impl", could be any of them)

The code in the base and the api package is always the same, the only thing that can change is one of the impls, for instance, I can introduce a new implementation.

Now I want to publish locally the api package depending on each of the implementations, by different names, for instance, one package called api-impl1, api-impl2 and so on.

One thing that I've tried is to do this one by one, which is not really a smart idea. So I was wondering if there's any dynamics to sbt to do this for me


Solution

  • if there's any dynamics to sbt to do this for me

    Yes, for example here I'm generating projects using Scala 2.13.0-2.13.13

    project/Build.scala

    import sbt.*
    import Keys.*
    
    object Build extends AutoPlugin {
      override def extraProjects: Seq[Project] = (0 to 13).map(i => {
        val name = s"proj2_13_$i"
        Project(name, file(name))
          .settings(scalaVersion := s"2.13.$i")
      })
    }
    

    enter image description here