0

I have the following dummy project structure:

|───employee-uService
|   ├───backend
|   |    ├───employee-api
|   |        ├───project
|   |        ├───src
|   |        │   └───main
|   |        │       ├───protobuf
|   |        │       └───scala
|   |        ├───build.sbt
|   ├───build.sbt
|───build.sbt (root project build)

The build.sbt in the employee-api contains project definition with the .settings(scalapbSettings(".")) setting. The scalapbSettings function sets up the proto source folder like:

val protoSources = PB.protoSources in Compile := Seq(file(s"$projectFolder/src/main/protobuf"))

Where the projectFolder is a parameter of the function.

The build.sbt one level higher in the hierarchy (employee-uService) defines employee-api and the respective impl project and aggregates them, while the root build aggregates the ...-uService projects.

Depending on the project I'm compiling, the given string parameter for the scalapbSettings function has to change to represent the proper path. (e.g.: in the root it has to be employee-uService/backend/employee-api while when running the api compile, it's ..

How could I pass a value to the function call that could be overwritten in the different build.sbt files?

Iamtazy
  • 5
  • 2

1 Answers1

0

Given the directory structure you described (protos are under src/main/protobuf in each project), you don't need to set PB.protoSources for each project since that is the default. However, if you wanted to specify it explicitly, and allow users to override, you could have in your scalapbSettings function the following line:

val protoSources = PB.protoSources in Compile := Seq(
    file((sourceDirectory in Compile).value / projectFolder))

Then projectFolder should be relative to src/main (and can have default value "protobuf" of)

Tip: in an SBT shell you can type, protocSources to see what is the value of this settings for each project.

thesamet
  • 6,382
  • 2
  • 31
  • 42