Coder Social home page Coder Social logo

sbt-protoc's Introduction

sbt-protoc

Travis CI AppVeyor

This plugin uses protoc to generate code from proto files. This SBT plugin is meant supercede sbt-protobuf and sbt-scalapb.

Highlights

  1. Uses protoc-jar by default (no need to install protoc)
  2. Generates source code directly under src_managed by default (works better with IntelliJ)
  3. Supports compiling protos in both test and compile configuration.
  4. Supports JVM-based code generators. Write your own custom code generator.
  5. Straightforward: No PB.protobufSettings, packaged as auto-plugin.

Installation

Step 1: create project/protoc.sbt with:

addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.15")

libraryDependencies += "com.trueaccord.scalapb" %% "compilerplugin" % "0.7.0"

Step 2: add to build.sbt:

If you only want to generate Java:

PB.targets in Compile := Seq(
  PB.gens.java -> (sourceManaged in Compile).value
)

For ScalaPB:

PB.targets in Compile := Seq(
  scalapb.gen() -> (sourceManaged in Compile).value
)

To generate Java + Scala with Java conversions:

PB.targets in Compile := Seq(
  PB.gens.java -> (sourceManaged in Compile).value,
  scalapb.gen(javaConversions = true) -> (sourceManaged in Compile).value
)

Step 3: Put some protos in src/main/protobuf and compile

Additional options

The options below need to be scoped to either Compile or Test (if unsure, you probably want Compile)

Example settings:

// Additional directories to search for imports:
PB.includePaths in Compile ++= Seq(file("/some/other/path"))

// Make protos from some Jar available to import.
libraryDependencies ++= Seq(
  "com.google.protobuf" % "protobuf-java" % "3.5.1" % "protobuf"
)

// Changing where to look for protos to compile (default src/main/protobuf):
PB.protoSources in Compile := Seq(sourceDirectory.value / "somewhere")

// Additional options to pass to protoc:
PB.protocOptions in Compile := Seq("-xyz")

// Excluding some proto files:
excludeFilter in PB.generate := "test-*.proto"

// Before version 0.99.15, when compiling in Windows, Python was used to bridge
// protoc and this JVM. To set the path for Python.exe:
// Note that this must be Python2 and not Python3.
// Sicne version 0.99.15 this option has no effect, and will be removed in a
// future version.
PB.pythonExe := "/path/to/python.exe"

// Rarely needed: override where proto files from library dependencies are
// extracted to:
PB.externalIncludePath := file("/tmp/foo")

// By default we generate into target/src_managed. To customize:
PB.targets in Compile := Seq(
  scalapb.gen() -> file("/some/other/dir")
)

// Use a locally provided protoc:
PB.runProtoc in Compile := (args => Process("/path/to/protoc", args)!)

The following setting is needed, if you want to generate .proto definitions in the Test scope.

inConfig(Test)(sbtprotoc.ProtocPlugin.protobufConfigSettings)

sbt-protoc's People

Contributors

thesamet avatar xuwei-k avatar masseguillaume avatar jacoby6000 avatar shinnya avatar jvican avatar jyane avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.