sbt-0.10.x plugin for compiling protobuf files
Clone or download
Pull request Compare This branch is 1 commit ahead, 164 commits behind sbt:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


A plugin for sbt-0.(10|11).x that transforms *.proto files into gazillion-loc java files.

The canonical repository for sbt-protobuf is now in the SBT organization


Adding the plugin dependency

In your project, create a file for plugin library dependencies project/plugins/build.sbt and add the following lines:


resolvers += "gseitz@github" at ""

libraryDependencies += "com.github.gseitz" %% "sbt-protobuf" % "0.2"


resolvers += "gseitz@github" at ""

addSbtPlugin("com.github.gseitz" % "sbt-protobuf" % "0.2.2")

Importing sbt-protobuf settings

To actually "activate" the plugin, its settings need to be included in the build.

import sbtprotobuf.{ProtobufPlugin=>PB}

seq(PB.protobufSettings: _*)
import sbtprotobuf.{ProtobufPlugin=>PB}

object MyBuild extends Build {
  lazy val MyProject(
    id = "myproject",
    base = file("."),
    settings = Defaults.defaultSettings ++ PB.protobufSettings ++ Seq( /* custom settings here */ )

Declaring dependencies

Assuming an artifact contains both *.proto files as well as the binaries of the generated *.java files, you can specify the dependency like so:

libraryDependencies += "some.groupID" % "some.artifactID" % "1.0" % // #1

libraryDependencies += "some.groupID" % "some.artifactID" % "1.0" // #2

Line #1 tells sbt-protobuf that the specified artifact contains *.proto files which it needs to extract and add to the includePath for protoc.

Line #2 adds the artifact to the regular compile:libraryDependencies.

The *.proto files of dependencies are extracted and added to the includePath parameter for protoc, but are not compiled.

Packaging proto files

*.proto files can be included in the jar file by adding the following setting to your build definition:

unmanagedResourceDirectories in Compile <+= (sourceDirectory in PB.protobufConfig).identity,

Changing the location of the generated java files

By default, the compiled proto files are created in <project-dir>/target/<scala-version>/src_managed/main/compiled_protobuf. Changing the location to <project-dir>/src/generated can be done by adding the following setting to your build definition:

javaSource in PB.protobufConfig <<= (sourceDirectory in Compile)(_ / "generated")

WARNING: The content of this directory is removed by the clean task. Don't set it to a directory containing files you hold dear to your heart.


All settings and tasks are in the protobuf scope. If you want to execute the generate task directly, just run protobuf:generate.


namename in shellbuilt-in keydefaultdescription
sourceDirectory source-directory x "src/main/protobuf"Path containing *.proto files.
javaSource java-source x "$sourceManaged/compiled_protobuf" Path for the generated *.java files.
version version x "2.4.1" Which version of the protobuf library should be used. A dependency to "" % "protobuf-java" % "$version" is automatically added to libraryDependencies
protoc protoc "protoc"The path to the 'protoc' executable.
includePaths include-paths Seq($generated-source, external-include-path)The path for additional *.proto files.
externalIncludePath external-include-path target/protobuf_externalThe path to which protobuf:library-dependencies are extracted and which is used as protobuf:include-path for protoc


generategeneratePerforms the hardcore compiling action and is automatically executed as a "source generator" in the Compile scope.
unpackDependenciesunpack-dependenciesExtracts proto files from library-dependencies into external-inlude-patch


sbt-protobuf is based on softprops/coffeescripted-sbt for the sbt-0.10 specific parts and codahale/protobuf-sbt for the protobuf specifics.