Autocompile Protobuf Files


Add the plugin,

addSbtPlugin(“com.github.gseitz” % “sbt-protobuf” % “0.6.3”)

to the plugins.sbt under the project[root-build] directory.

Add the following libraries to the build.sbt in the library dependencies: “” % “protobuf-java” % (version in ProtobufConfig).value %, and

“com.googlecode.protobuf-java-format” % “protobuf-java-format” % “1.4”

Next add the following statements out side the library dependencies:

—- Changing the default generated source directory location from ‘src_managed’ in ‘target’ to ‘generated-source’ under ‘app’ directory —-

javaSource in ProtobufConfig := baseDirectory.value / “app” / “generated-source”

— Enable the Protobuf Plugin using the below statement–


Note: Make sure the name of the folder residing *.proto files is ‘protobuf’, since it is the default name to identify the *.proto files location to compile & generate protobuf classes. Finally run the `sbt shell` or `SBTConsole` to clean & compile in order to generate the protobuf classes in “generated-source” directory.

NOTE: Any changes made to the build.sbt file will not take effect until we kill the current process in `sbt shell` or `SBTConsole` & start a new one again.

Replacing proto path using REGEX

Replacing proto path using REGEX

Find & replace “import paths” in .proto files:

The following command will replace the text ‘enums/’ to ‘enums’ removing the forward slash in the entire directory consisting of .proto files.

NOTE: Make sure to give the complete text while searching to replace appropriately at the desired locations.

find ./ -name \*.proto -exec sed -i “s;enums/;\\enums;g” {} \;


The text ‘enums/’ is the text to find in the proto files & the ‘enums’ text after the double back slash is the one to be replaced.

Protobuf: Migrating from proto2.6 to proto3

Uninstall protobuf-compiler
To remove just protobuf-compiler package itself from Ubuntu

sudo apt-get remove protobuf-compiler
Uninstall protobuf-compiler and it’s dependent packages
To remove the protobuf-compiler package and any other dependant package which are no longer needed from Ubuntu.

sudo apt-get remove –auto-remove protobuf-compiler
Purging protobuf-compiler
If you also want to delete configuration and/or data files of protobuf-compiler from Ubuntu

sudo apt-get purge protobuf-compiler

To delete configuration and/or data files of protobuf-compiler and it’s dependencies from Ubuntu Trusty then execute:

sudo apt-get purge –auto-remove protobuf-compiler

Once uninstalled, installation for proto3 follow the steps as described below

curl -OL

unzip -d protoc3 

Note: run command ‘sudo apt install unzip’ if the program ‘unzip’ is currently not installed.

sudo mv protoc3/bin/* /usr/local/bin/

sudo mv protoc3/include/* /usr/local/include/


To check where protbuf compiler is installed or the version of the protobuf compiler,

user@LT-201:~/Downloads$ which protoc
user@LT-201:~/Downloads$ protoc –version
libprotoc 3.2.0