Skip to content

Commit

Permalink
update readme to reflect support of workspaces and basic buf projects
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewparmet committed Apr 10, 2022
1 parent ef526a9 commit c378a96
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,17 @@
[![Maven Central](https://img.shields.io/badge/dynamic/xml?color=orange&label=maven-central&prefix=v&query=%2F%2Fmetadata%2Fversioning%2Flatest&url=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fcom%2Fparmet%2Fbuf-gradle-plugin%2Fmaven-metadata.xml)](https://search.maven.org/artifact/com.parmet/buf-gradle-plugin)
[![Gradle Portal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/com/parmet/buf-gradle-plugin/maven-metadata.xml.svg?label=gradle-portal&color=yellowgreen)](https://plugins.gradle.org/plugin/com.parmet.buf)

Linting and breakage-check integration for [Buf](https://github.com/bufbuild/buf) with the
[protobuf-gradle-plugin](https://github.com/google/protobuf-gradle-plugin).
Linting and breakage-check integration for [Buf](https://github.com/bufbuild/buf) with Gradle. Supports integration purely between Buf and Gradle or additionally with the [protobuf-gradle-plugin](https://github.com/google/protobuf-gradle-plugin).

Supports straightforward usage of `buf lint` and a self-contained integration between `buf build` and `buf breaking`. Does not integrate with `buf generate` as it assumes usage of the `protobuf-gradle-plugin` for dependency resolution and code generation.
This plugin supports straightforward usage of `buf lint` and a self-contained integration between `buf build` and `buf breaking`. It does not (yet) integrate with `buf generate`.

## Usage

Make sure you have applied the `protobuf-gradle-plugin` to your project.
By default this plugin assumes that Buf is configured for the project root (with or without a workspace `buf.work.yaml`). It will scan all top-level directories for protobuf sources.

Optionally create a Buf configuration file in the project directory:
If the project includes the `protobuf-gradle-plugin`, then this plugin will use an implicit Buf workspace that includes all specified protobuf source set directories, the `include` dependencies that the protobuf-gradle-plugin extracts into `"${project.buildDir}/extracted-include-protos"`, and the dependencies that the protobuf-gradle-plugin has been told to generate that are extracted into `"${project.buildDir}/extracted-protos"`.

``` yaml
# buf.yaml

version: v1
lint:
ignore:
- path/to/dir/to/ignore
use:
- DEFAULT
```
This plugin works with an implicit Buf workspace that includes all specified protobuf source set directories, the `include` dependencies that the protobuf-gradle-plugin extracts into `"${project.buildDir}/extracted-include-protos"`, and the dependencies that the protobuf-gradle-plugin has been told to generate that are extracted into `"${project.buildDir}/extracted-protos"`.

See [below](#configuration) for alternative methods of configuration.
This plugin does not support usage of both a Buf workspace and the `protobuf-gradle-plugin`; determining ownership of dependency resolution in that case would be complicated and error-prone.

Apply the plugin:

Expand All @@ -51,22 +37,32 @@ apply(plugin = "com.parmet.buf")

When applied the plugin creates two useful tasks:
- `bufLint` lints protobuf code
- `bufBreaking` checks protobuf against a previous version for
backwards-incompatible changes.
- `bufBreaking` checks protobuf against a previous version for backwards-incompatible changes

## Configuration

As an alternative to a `buf.yaml` file in the project directory you can specify
the location of `buf.yaml` by configuring the extension:
For a basic Buf project or one that uses the `protobuf-gradle-plugin` you can create a Buf configuration file in the project directory:

``` yaml
# buf.yaml

version: v1
lint:
ignore:
- path/to/dir/to/ignore
use:
- DEFAULT
```
As an alternative to a `buf.yaml` file in the project directory you can specify the location of `buf.yaml` by configuring the extension:

``` kotlin
buf {
configFileLocation = rootProject.file("buf.yaml")
}
```

Or you can share a Buf configuration across projects and specify it via the
dedicated `buf` configuration:
Or you can share a Buf configuration across projects and specify it via the dedicated `buf` configuration:

``` kotlin
dependencies {
Expand Down Expand Up @@ -102,10 +98,11 @@ publishing {
}
```

Projects with Buf workspaces must configure their workspaces as described in the Buf documentation; no configuration for linting will be overrideable. A `buf.yaml` in the project root or specified in the extension will be used for breakage checks only.

### `bufLint`

`bufLint` is configured solely through `buf.yaml` and follows Buf's
standard CLI behavior.
`bufLint` is configured by creating `buf.yaml` in basic projects or projects using the `protobuf-gradle-plugin`. Lint configuration at the Gradle plugin level is not supported for projects using a Buf workspace.

### `bufBreaking`

Expand Down Expand Up @@ -145,9 +142,7 @@ src/main/proto/parmet/service/test/test.proto:9:1:Previously present field "1" w

#### Checking against a static version

If for some reason you do not want to dynamically check against the latest
published version of your schema, you can specify a constant version with
`previousVersion`:
If for some reason you do not want to dynamically check against the latest published version of your schema, you can specify a constant version with `previousVersion`:

``` kotlin
buf {
Expand Down Expand Up @@ -177,8 +172,7 @@ buf {

## Additional Configuration

The version of Buf used can be configured using the `toolVersion` property on
the extension:
The version of Buf used can be configured using the `toolVersion` property on the extension:

``` kotlin
buf {
Expand Down

0 comments on commit c378a96

Please sign in to comment.