This is a Proof of Concept project that demonstrates how to compile protobuf file
that depends on another external protobuf file that lives in another git repository.
- sbt
- sbt-protoc plugin to compile .proto files to .java .scala classes
- SSH key (in
~/.ssh/
) to access private git repository
- If you need to reference a sbt sub-project from the github repository:
lazy val sbtProjectFromOtherGitRepo = ProjectRef( build = uri("ssh://git@github.com/<user>/<repo>.git#<branch|commit|tag>"), project = "sub-project" )
- Else just specify github repository:
lazy val projectFromOtherGitRepo = RootProject( build = uri("ssh://git@github.com/<user>/<repo>.git#<branch|commit|tag>") )
Dependency projects will be cloned/checkouted to: ~/.sbt/<sbt version>/staging/<sha>/<repo>/
- Then using
sbt-protoc
specify location of .proto files from project dependency:PB.protoSources in Compile ++= Seq( baseDirectory.in(projectFromOtherGitRepo).value / "path/to/folder/where/protos/are" )
git clone git@github.com:fpopic/sbt-ssh-git-proto-deployment-poc.git
cd sbt-ssh-git-proto-deployment-poc
sbt
compile
External projects that the current project depends on (RootProject
) are not getting updated using sbt update
command after they have been changed in git,
(that’s reason why it’s always better to hardcode “immutable” commit/tag version of the dependency than just specifying the repository name), so if a dependend project changes sbt won’t reupdate the source code of the dependency
-
Workaround is to delete sbt staging folder before update so the project will always clone from git
rm -r ~/.sbt/<sbt version>/staging/ sbt update
You can maybe create a sbt external task and name it cleanStagingAndUpdate
-
Or use sbt for downloading git repos and then
publishLocal
to get .jar and add jar tolibraryDependencies
instead ofdependsOn(project)
This PoC is made for CI automatization (Jenkins) for deploying proto files to maven repository (every time cloning from scratch)
Leave a Reply