google / google/protobuf-gradle-plugin

Consider using Gradle configurations instead of protobuf extension for easier end-user API

Open
#628 11 comments 5 reactions 0 assignees View on GitHub
enhancement
Dominant language
Groovy
Stars
1.8k
Forks
288
PR merge metrics
No merged PRs in 30d

Description

Current protobuf-gradle-plugin API requires 25 lines in `gradle.build.kts` (16 without comments) for the most common trivial case: https://github.com/google/protobuf-gradle-plugin/blob/d6f7cffca453d47e34d70865b5b51012d773426e/examples/exampleKotlinDslProject/build.gradle.kts#L35-L59

It looks like an unnecessary complication, so I wonder what would you think of providing the following API instead:

```kotlin
dependencies {
// A configuration where end-users could declare the relevant protobuf dependency
protobufCompiler("com.google.protobuf:protoc:3.21.7")
// Plain files are supported by Gradle: https://docs.gradle.org/current/userguide/declaring_dependencies.html#sub:file_dependencies
// protobufCompiler(files("/path/to/protobuf/compiler"))

// I'm not sure regarding the name, however, the idea is that each sourceSet
// could create a configuration for attaching "protoc plugins" just like "implementation, api, compileOnly, etc" configurations
// are created for each source set
// Let us imagine that protobufPlugin("...") declares dependencies for "protoc tasks for the main source set"
protobufPlugin("io.grpc:protoc-gen-grpc-java:1.50.0")

// testProtobufPlugin declares dependencies for "protoc tasks for the test source set" (~ like testImplementation)
testProtobufPlugin("io.grpc:protoc-gen-grpc-java:1.50.0")
}
```

That completely removes the need for `protobuf { plugins {...}, generateProtoTasks { of...}`, and I believe, it makes the common case much easier to understand and manage.

In other words, "adding protobuf-gradle-plugin" would look as follows:

```diff
plugins {
id("java-library")
+ id("com.google.protobuf") version "0.8.19"
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
+ protobufCompiler("com.google.protobuf:protoc:3.21.7")
+ protobufPlugin("io.grpc:protoc-gen-grpc-java:1.50.0")
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.