Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
sbt-0.10.x plugin for compiling protobuf files
branch: scalabuff

This branch is even with sbt:scalabuff

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


A plugin for sbt-0.10.x that transforms *.proto files into scala files via SandroGrzicic/ScalaBuff


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 ""

addSbtPlugin("com.github.gseitz.sbt-protobuf" % "scalabuff" % "0.3-SNAPSHOT") // requires sbt-0.11.x

Importing sbt-protobuf settings

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

import sbtprotobuf.{ScalaBuffPlugin=>SB}

seq(SB.scalaBuffSettings: _*)
import sbtprotobuf.{ScalaBuffPlugin=>SB}

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

Declaring dependencies

Assuming an artifact contains both *.proto files as well as the binaries of the generated *.scala 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 ScalaBuff, 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 SB.scalaBuffConfig).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:

generatedSource in SB.scalaBuffConfig <<= (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 scalabuff scope. If you want to execute the generate task directly, just run scalabuff:generate.


name name in shell built-in key default description
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_external The path to which protobuf:library-dependencies are extracted and which is used as protobuf:include-path for protoc


name shell-name description
generate generate Performs the hardcore compiling action and is automatically executed as a "source generator" in the Compile scope.
unpackDependencies unpack-dependencies Extracts 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.

Something went wrong with that request. Please try again.