{"id":19248972,"url":"https://github.com/sbt/sbt-protobuf","last_synced_at":"2025-04-13T04:16:27.216Z","repository":{"id":899967,"uuid":"1980781","full_name":"sbt/sbt-protobuf","owner":"sbt","description":"sbt plugin for compiling protobuf files","archived":false,"fork":false,"pushed_at":"2025-03-17T07:49:28.000Z","size":317,"stargazers_count":172,"open_issues_count":4,"forks_count":41,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-13T04:16:13.343Z","etag":null,"topics":["protobuf","protocol-buffers","sbt","sbt-plugin","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sbt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-06-30T23:03:21.000Z","updated_at":"2025-03-17T07:49:33.000Z","dependencies_parsed_at":"2023-07-05T19:33:57.137Z","dependency_job_id":"8311aa85-ea22-41a9-b52f-e1958438be78","html_url":"https://github.com/sbt/sbt-protobuf","commit_stats":{"total_commits":395,"total_committers":16,"mean_commits":24.6875,"dds":0.6075949367088608,"last_synced_commit":"6272304c55b8e84e7f8abcd4e0c7a070641014e8"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbt%2Fsbt-protobuf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbt%2Fsbt-protobuf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbt%2Fsbt-protobuf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbt%2Fsbt-protobuf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbt","download_url":"https://codeload.github.com/sbt/sbt-protobuf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248661716,"owners_count":21141451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["protobuf","protocol-buffers","sbt","sbt-plugin","scala"],"created_at":"2024-11-09T18:11:49.328Z","updated_at":"2025-04-13T04:16:27.182Z","avatar_url":"https://github.com/sbt.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sbt-protobuf\nA plugin for sbt that transforms `*.proto` files into gazillion-loc Java source files, and potentially to other languages too.\n\n\n## Usage\n\n### Adding the plugin dependency\nIn your project, create a file for plugin library dependencies `project/plugins.sbt` and add the following line:\n\n```scala\naddSbtPlugin(\"com.github.sbt\" % \"sbt-protobuf\" % \"0.8.1\")\n```\n\nThe dependency to `\"com.google.protobuf\" % \"protobuf-java\"` is automatically added to the `Compile` scope.\nThe version for `protobuf-java` can be controlled by the setting `ProtobufConfig / version` (set to `3.9.0` by default).\n\n### Importing sbt-protobuf settings\nTo actually \"activate\" the plugin, its settings need to be included in the build.\n\n##### build.sbt\n\n```scala\nenablePlugins(ProtobufPlugin)\n```\n\n\n### Declaring dependencies\n#### Artifacts containing both `*.proto` files and java binaries\nAssuming an artifact contains both `*.proto` files as well as the binaries of the generated `*.java` files, you can specify the dependency like so:\n\n```scala\nlibraryDependencies += \"some.groupID\" % \"some.artifactID\" % \"1.0\" % ProtobufConfig.name // #1\n\nlibraryDependencies += \"some.groupID\" % \"some.artifactID\" % \"1.0\" // #2\n```\n\nLine #1 tells `sbt-protobuf` that the specified artifact contains *.proto files which it needs to extract and add to the `--proto_path` for `protoc`.\nInternally the setting `protobufExternalIncludePath` is used to track 3rd party proto files.\n\nLine #2 adds the artifact to the regular compile classpath.\n\nThe `*.proto` files of dependencies are extracted and added to the `--proto_path` parameter for `protoc`, but are not compiled.\n\n#### Artifacts in the `protobuf` configuration containing only `*.proto` files\nYou can specify a dependency on an artifact that contains only `.proto` files in the `protobuf` configuration with a `proto` classifier like so:\n```\nlibraryDependencies += (\"some.groupID\" % \"some.artifactID\" % \"1.0\" classifier protoClassifier) % s\"${ProtobufConfig.name}-\u003e${ProtobufConfig.name}\"\n```\n\n### Compiling external proto files\nSometimes it's desirable to compile external proto files (eg. because the library is compiled with an older version of `protoc`).\nThis can be achieved by adding the following setting:\n\n```scala\nProtobufConfig / sourceDirectories += (ProtobufConfig / protobufExternalIncludePath).value\n```\n\n### Compiling gRPC proto files\nThe following enables gRPC support.\n\n```scala\nProtobufConfig / protobufGrpcEnabled := true\n```\n\n### Packaging proto files\n`*.proto` files can be included in the jar file by adding the following setting to your build definition:\n\n```scala\nCompile / unmanagedResourceDirectories += (ProtobufConfig / sourceDirectory).value\n```\n\nAlternatively, `*.proto` files can be packaged in a separate jar file in the `protobuf` configuration with a `proto` classifier:\n\n```scala\naddArtifact(ProtobufConfig / protobufPackage / artifact, ProtobufConfig / protobufPackage)\n```\n\n### Changing the location of the generated java files\nBy default, the compiled proto files are created in `\u003cproject-dir\u003e/target/\u003cscala-version\u003e/src_managed/main/compiled_protobuf`. Changing the location to `\u003cproject-dir\u003e/src/generated` can be done by adding the following setting to your build definition:\n\n```scala\nProtobufConfig / javaSource := ((Compile / sourceDirectory).value / \"generated\")\n```\n\n**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.\n\n### Note\n\n1. If you encounter compile errors, as ```[...] is already defined as object [...]``` you could change the compile order\nas ```compileOrder := CompileOrder.JavaThenScala```,the default is ```mixed```.\n\n2. The inner message's name could not be the ```.proto```'s file name.that will cause problem too, you could change the inner message's name or the ```.proto``` file name or add the ```option java_outer_classname = \"NewNameNotAsTheFileName\";``` to you ```.proto``` file.\n\n### Additional options to protoc\nAll options passed to `protoc` are configured via the `protobufProtocOptions`. To add options, for example to run a custom plugin, add them to this setting key. For example:\n\n```scala\nProtobufConfig / protobufProtocOptions ++= Seq(\"--custom-option\")\n```\n\n### Additional target directories\nThe source directories where the files are generated, and the globs used to identify the generated files, are configured by `ProtobufConfig / protobufGeneratedTargets`.\nIn case only Java files are generated, this setting doesn't need to change, since it automatically inherits the value of `ProtobufConfig / javaSource`, paired with the glob `*.java`.\nIn case other types of source files are generated, for example by using a custom plugin (see previous section), the corresponding target directories and source file globs must be configured by adding them to this setting. For example:\n\n```scala\nProtobufConfig / protobufGeneratedTargets ++= {\n  Seq(((Compile / sourceDirectory).value / \"generated\" / \"scala\", \"*.scala\"))\n}\n```\n\nThis plugin uses the `protobufGeneratedTargets` setting to:\n- add the generated source directories to `cleanFiles` and `managedSourceDirectories`\n- collect the generated files after running `protoc` and return them to SBT for the compilation phase\n\n## Scope\nAll settings and tasks are in the `protobuf` scope. If you want to execute the `protobufGenerate` task directly, just run `protobuf:protobufGenerate`.\n\n\n\n## Settings\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003ename\u003c/th\u003e\u003cth\u003ebuilt-in key\u003c/th\u003e\u003cth\u003edefault\u003c/th\u003e\u003cth\u003edescription\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003esourceDirectory\u003c/td\u003e\n    \u003ctd\u003ex\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\"src/main/protobuf\"\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003ePath containing \u003ccode\u003e*.proto\u003c/code\u003e files.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003esourceDirectories\u003c/td\u003e\n    \u003ctd\u003ex\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003esourceDirectory\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003eThis setting is used to collect all directories containing \u003ccode\u003e*.proto\u003c/code\u003e files to compile\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003ejavaSource\u003c/td\u003e\n    \u003ctd\u003ex\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\"$sourceManaged/compiled_protobuf\"\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003ePath for the generated \u003ccode\u003e*.java\u003c/code\u003e files.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003eversion\u003c/td\u003e\n    \u003ctd\u003ex\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\"3.25.3\"\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003eWhich version of the protobuf library should be used. A dependency to \u003ccode\u003e\"com.google.protobuf\" % \"protobuf-java\" % \"$version\"\u003c/code\u003e is automatically added to \u003ccode\u003elibraryDependencies\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003eprotobufGrpcVersion\u003c/td\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\"1.62.2\"\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003eWhich version of the gRPC plugin should be used.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003eprotobufGrpcEnabled\u003c/td\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003efalse\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003eThe setting to enable gRPC plugin.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003eprotobufProtoc\u003c/td\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\"protoc\"\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003eThe path to the 'protoc' executable.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003eprotobufIncludeFilters\u003c/td\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003eGlob(d.toPath()) / \"**\" / \"*.proto\"\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003eThe list of \u003ccode\u003e*.proto\u003c/code\u003e glob expressions to include.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003eprotobufExcludeFilters\u003c/td\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003eGlob(d.toPath()) / \"google\" / \"protobuf\" / \"*.proto\"\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003eThe list of \u003ccode\u003e*.proto\u003c/code\u003e glob expressions to exclude.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003eprotobufIncludePaths\u003c/td\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003eSeq($generated-source, protobufExternalIncludePath)\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003eThe path for additional \u003ccode\u003e*.proto\u003c/code\u003e files.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003eprotobufExternalIncludePath\u003c/td\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003etarget/protobuf_external\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003eThe path to which \u003ccode\u003eprotobuf:libraryDependencies\u003c/code\u003e are extracted and which is used as \u003ccode\u003eprotobuf:protobufIncludePath\u003c/code\u003e for \u003ccode\u003eprotoc\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003eprotobufGeneratedTargets\u003c/td\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e(file(\u003c/code\u003ejava source directory based on \u003ccode\u003eProtobufConfig / javaSource\u003c/code\u003e), \u003ccode\u003e\"*.java\")\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003eThe list of target directories and source file globs for the generated files\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n## Tasks\n\n\u003ctable\u003e\n\u003ctr\u003e\n  \u003cth\u003ename\u003c/th\u003e\n  \u003cth\u003edescription\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd\u003eprotobufGenerate\u003c/td\u003e\n  \u003ctd\u003ePerforms the hardcore compiling action and is automatically executed as a \"source generator\" in the \u003ccode\u003eCompile\u003c/code\u003e scope.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd\u003eprotobufUnpackDependencies\u003c/td\u003e\n  \u003ctd\u003eExtracts proto files from \u003ccode\u003elibraryDependencies\u003c/code\u003e into \u003ccode\u003eprotobufExternalInludePatch\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd\u003eprotobufRunProtoc\u003c/td\u003e\n  \u003ctd\u003eA function that executes the protobuf compiler with the given arguments,\n    returning the exit code. The default implementation runs the executable referenced by the \u003ccode\u003eprotoc\u003c/code\u003e setting.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd\u003eprotobufPackage\u003c/td\u003e\n  \u003ctd\u003eProduces a jar artifact containing only \u003ccode\u003e*.proto\u003c/code\u003e files, with a \u003ccode\u003eproto\u003c/code\u003e classifier\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n    \u003ctd\u003eprotobufProtocOptions\u003c/td\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e--java_out=\u003c/code\u003e[java generated source directory from \u003ccode\u003eprotobufGeneratedTargets\u003c/code\u003e]\u003c/td\u003e\n    \u003ctd\u003eThe list of options passed to the \u003ccode\u003eprotoc\u003c/code\u003e binary\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003c/table\u003e\n\n## IntelliJ IDEA BSP bug\nIntelliJ has a [bug](https://youtrack.jetbrains.com/issue/SCL-19517) where it only recognizes generated sources if there is at least one Scala class in the same package - otherwise you'll see red squiggles. As a workaround, you can configure your project to add a private empty class, e.g. like this:\n```scala\nCompile / sourceGenerators += Def.task {\n  // adapt this for your build:\n  val protoPackage = \"org.example.proto.foo\"\n\n  val scalaFile = (Compile/sourceManaged).value / \"_ONLY_FOR_INTELLIJ.scala\"\n\n  IO.write(scalaFile,\n    s\"\"\"package $protoPackage\n      |\n      |private class _ONLY_FOR_INTELLIJ\n      |\"\"\".stripMargin)\n\n  Seq(scalaFile)\n}.taskValue\n```\n\n## Credits\n`sbt-protobuf` is based on [softprops/coffeescripted-sbt](https://github.com/softprops/coffeescripted-sbt) for the sbt-0.10 specific parts and [codahale/protobuf-sbt](https://github.com/codahale/protobuf-sbt) for the protobuf specifics.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbt%2Fsbt-protobuf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbt%2Fsbt-protobuf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbt%2Fsbt-protobuf/lists"}