1

I have a centralized repo maintaining a set of proto files used across a multitude of projects. I want to be able to download this into my resources before the ScalaPB compiles proto into corresponding case classes. I've seen some examples using dependsOn, but this repo is not a sbt project.

How would I go about this?

J.Fratzke
  • 1,415
  • 15
  • 23

1 Answers1

1

Consider defining a custom task to download files into local resources directory like so

lazy val remoteProtoFiles = taskKey[Unit]("Download proto files from remote repository into local resources directory")
remoteProtoFiles := {
  import scala.sys.process._
  streams.value.log.info("Downloading proto files from remote repository into local resources directory...")
  val externalResources = "https://my-external-repo/protofiles/"
  val protoFiles = List("foo.proto", "bar.proto")
  val resources = (Compile / resourceDirectory).value
  protoFiles.foreach { protoFile =>
    url(s"$externalResources/$protoFile") #> (resources / protoFile) !
  }
}

and then have compile task depend on remoteProtoFiles task like so

compile in Compile := (compile in Compile).dependsOn(remoteProtoFiles).value

Now executing sbt compile should download proto files into yourProject/src/main/resources before compilation executes.

Mario Galic
  • 47,285
  • 6
  • 56
  • 98