DEV Community

Leandro Boeing Vieira
Leandro Boeing Vieira

Posted on

gRPC + Spring Boot application compiling proto files as a dependency

If you're working with gRPC you're probably also working with Protobuf. And manually sharing your proto files with clients may not scale well.

What if I tell you that you could have a separated project and share your proto files as gradle/maven dependencies? That's the main goal of this article. Of course there'll be many more ways do to it out there, but if you use this article as a guide to do better, I'll be really honored.

So, I created 2 projects on Github:

Noticed the names? One of them ends with "-proto". Yes, that's the project where we'll keep the proto files related to the "grpc-hexagonal-architecture" service. Oh, you're telling me you also noticed the names "hexagonal architecture"? That's a talk for another article. Let's focus on sharing the proto files in this one. And similarly I created 2 maven projects with the very same names.

The structure of the "proto project" is really simple:


No java classes, no extra configuration, just a pom file and a src folder. But if you pay attention to the pom file you'll wanna look at two parts:

  • The <>
  • The maven-release-plugin

The <> tag only exists to support multiple Github users on the same machine. If you only have one user, please define it with the value "". In my case, "" refers to the repositories I use in my job and for my personal repositories I use "github-lepsistemas". Please, refer to this article if you need help with it:

The maven-release-plugin will allow you to create tags and releases for your project in Github. For that, you'll need to be working on a SNAPSHOT (<version>1.0.0-SNAPSHOT</version>) and then you need to execute the maven task:

mvn -B release:clean release:prepare release:perform
Enter fullscreen mode Exit fullscreen mode

This will create tag and release 1.0.0 in Github and will increase your local pom to 1.0.1-SNAPSHOT version.

At this point you have a release available in Github and you could download it as a dependency in another project. We'll use it in "grpc-hexagonal-architecture", another maven project.

Along with the dependencies that the project needs to compile/test/run, you'll also need this under <project> tag:

Enter fullscreen mode Exit fullscreen mode

This will allow you to download a dependency directly from Github.

Add the dependency under the <dependencies> tag:

Enter fullscreen mode Exit fullscreen mode

And configure the compiler like this under the <plugins> tag:

Enter fullscreen mode Exit fullscreen mode

All set. Your new gRPC project has a dependency from another project that exposes only the proto files. If you have any doubts, please refer to the Github repositories or you can always ask me.

Top comments (0)