From c2a43c2f8759b9ec576ebe950517bd5e04d9ea51 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 28 May 2025 12:52:19 +0100 Subject: [PATCH] Attempt to fix plugin mess --- README.md | 22 ++--- samples/grpc-client/build.gradle | 80 +++++++++------- samples/grpc-oauth2/build.gradle | 94 ++++++++++--------- samples/grpc-reactive/build.gradle | 16 +++- samples/grpc-secure/build.gradle | 86 +++++++++-------- samples/grpc-server-kotlin/build.gradle | 7 ++ samples/grpc-server-netty-shaded/build.gradle | 14 ++- samples/grpc-server/build.gradle | 16 +++- samples/grpc-tomcat-secure/build.gradle | 16 +++- samples/grpc-tomcat/build.gradle | 14 ++- samples/grpc-webflux/build.gradle | 14 ++- .../modules/ROOT/pages/getting-started.adoc | 2 +- 12 files changed, 225 insertions(+), 156 deletions(-) diff --git a/README.md b/README.md index 087906e..49e6713 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ For further information go to our [Spring gRPC reference documentation](https:// # Getting Started -This section offers jumping off points for how to get started using Spring gRPC. There is a simple sample project in the `samples` directory (e.g. [`grpc-server`](https://github.com/spring-projects/spring-grpc/tree/main/samples/grpc-server)). You can run it with `./mvnw spring-boot:run` or `./gradlew bootRun`. You will see the following code in that sample. +This section offers jumping off points for how to get started using Spring gRPC. There is a simple sample project in the `samples` directory (e.g. [`grpc-server`](https://github.com/spring-projects/spring-grpc/tree/main/samples/grpc-server)). You can run it with `mvn spring-boot:run` or `gradle bootRun`. You will see the following code in that sample. Want to get started? Let’s speedrun a working service. @@ -19,15 +19,13 @@ Generate the project and unzip the downloaded result. Open it in your IDE in the usual way. E.g. if you’re using IntelliJ IDEA: `idea pom.xml`; or for VSCode `code .`. -Define a `.proto` service definition file `src/main/proto/hello.proto` with the following contents: - -IMPORTANT: Be sure to change the `java_package` to the one you chose in Spring Initializr +Define a `.proto` service definition file `src/main/protobuf/hello.proto` with the following contents: ```proto syntax = "proto3"; option java_multiple_files = true; -option java_package = ".proto"; +option java_package = "org.springframework.grpc.sample.proto"; option java_outer_classname = "HelloWorldProto"; // The greeting service definition. @@ -60,15 +58,7 @@ or ./gradlew build ``` -Two new folders will be generated containing the source code for the stubs. - -_For Maven_: `target/generated-sources/protobuf/grpc-java` and `target/generated-sources/protobuf/java`. - -_For Gradle_: `build/generated/source/proto/main/grpc` and `build/generated/source/proto/main/java`) - -You may need to instruct your IDE to mark them as source roots. -In IntelliJ IDEA, right-click the folder, choose `Mark Directory As` -> `Generated Source Root`. -Eclipse or VSCode will add them automatically for you. +You’ll get two new folders in the `target` directory (or `build` for Gradle): `target/target/generated-sources/protobuf/grpc-java` and `target/target/generated-sources/protobuf/java`. You may need to instruct your IDE to mark them as source roots. In IntelliJ IDEA, you’d right click the folder, choose `Mark Directory As` -> `Generated Source Root`. Eclipse or VSCode will add them automatically for you. Now you can implement a service based on the generated stubs: @@ -122,7 +112,7 @@ Run the program in the usual way: or ```shell -./gradlew bootRun +./gradle bootRun ``` You can try it out using a gRPC client like `grpcurl`: @@ -254,7 +244,7 @@ public class GrpcServerApplication { } ``` -Run it from your IDE, or on the command line with `./mvnw spring-boot:run` or `./gradlew bootRun`. +Run it from your IDE, or on the command line with `mvn spring-boot:run` or `gradle bootRun`. ### gRPC Client diff --git a/samples/grpc-client/build.gradle b/samples/grpc-client/build.gradle index 6b59a0c..65c0135 100644 --- a/samples/grpc-client/build.gradle +++ b/samples/grpc-client/build.gradle @@ -1,59 +1,67 @@ plugins { - id 'java' - id 'org.springframework.boot' version '3.5.0' - id 'io.spring.dependency-management' version '1.1.6' - id 'com.google.protobuf' version '0.9.4' + id 'java' + id 'org.springframework.boot' version '3.5.0' + id 'io.spring.dependency-management' version '1.1.6' + id 'com.google.protobuf' version '0.9.4' } group = 'com.example' version = '0.9.0-SNAPSHOT' java { - toolchain { - languageVersion = JavaLanguageVersion.of(17) - } + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } } repositories { - mavenLocal() - mavenCentral() - maven { url 'https://repo.spring.io/milestone' } - maven { url 'https://repo.spring.io/snapshot' } + mavenLocal() + mavenCentral() + maven { url 'https://repo.spring.io/milestone' } + maven { url 'https://repo.spring.io/snapshot' } } dependencyManagement { - imports { - mavenBom 'org.springframework.grpc:spring-grpc-dependencies:0.9.0-SNAPSHOT' - } + imports { + mavenBom 'org.springframework.grpc:spring-grpc-dependencies:0.9.0-SNAPSHOT' + } } dependencies { - implementation 'org.springframework.grpc:spring-grpc-client-spring-boot-starter' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testImplementation 'org.springframework.grpc:spring-grpc-test' - testImplementation 'org.springframework.experimental.boot:spring-boot-testjars-maven:0.0.3' - testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + implementation 'org.springframework.grpc:spring-grpc-client-spring-boot-starter' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.springframework.grpc:spring-grpc-test' + testImplementation 'org.springframework.experimental.boot:spring-boot-testjars-maven:0.0.3' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } tasks.named('test') { - useJUnitPlatform() + useJUnitPlatform() +} + +sourceSets { + main { + proto { + srcDir 'src/main/protobuf' + } + } } protobuf { - protoc { - artifact = "com.google.protobuf:protoc:${dependencyManagement.importedProperties['protobuf-java.version']}" - } - plugins { - grpc { - artifact = "io.grpc:protoc-gen-grpc-java:${dependencyManagement.importedProperties['grpc.version']}" - } - } - generateProtoTasks { - all()*.plugins { - grpc { - option 'jakarta_omit' - option '@generated=omit' - } - } - } + protoc { + artifact = "com.google.protobuf:protoc:${dependencyManagement.importedProperties['protobuf-java.version']}" + } + plugins { + grpc { + artifact = "io.grpc:protoc-gen-grpc-java:${dependencyManagement.importedProperties['grpc.version']}" + } + } + generateProtoTasks { + all()*.plugins { + grpc { + option 'jakarta_omit' + option '@generated=omit' + } + } + } } diff --git a/samples/grpc-oauth2/build.gradle b/samples/grpc-oauth2/build.gradle index ea12656..01ae2cd 100644 --- a/samples/grpc-oauth2/build.gradle +++ b/samples/grpc-oauth2/build.gradle @@ -1,69 +1,77 @@ plugins { - id 'java' - id 'org.springframework.boot' version '3.5.0' - id 'io.spring.dependency-management' version '1.1.6' - id 'org.graalvm.buildtools.native' version '0.10.3' - id 'com.google.protobuf' version '0.9.4' + id 'java' + id 'org.springframework.boot' version '3.5.0' + id 'io.spring.dependency-management' version '1.1.6' + id 'org.graalvm.buildtools.native' version '0.10.3' + id 'com.google.protobuf' version '0.9.4' } group = 'com.example' version = '0.9.0-SNAPSHOT' java { - toolchain { - languageVersion = JavaLanguageVersion.of(17) - } + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } } processTestAot { - enabled = false + enabled = false } repositories { - mavenCentral() - maven { url 'https://repo.spring.io/milestone' } - maven { url 'https://repo.spring.io/snapshot' } + mavenCentral() + maven { url 'https://repo.spring.io/milestone' } + maven { url 'https://repo.spring.io/snapshot' } } dependencyManagement { - imports { - mavenBom 'org.springframework.grpc:spring-grpc-dependencies:0.9.0-SNAPSHOT' - } + imports { + mavenBom 'org.springframework.grpc:spring-grpc-dependencies:0.9.0-SNAPSHOT' + } } dependencies { - implementation 'org.springframework.grpc:spring-grpc-spring-boot-starter' - implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' - implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' - implementation 'org.springframework.boot:spring-boot-starter-security' - implementation 'io.grpc:grpc-services' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testImplementation 'org.springframework.grpc:spring-grpc-test' - testImplementation 'org.springframework.experimental.boot:spring-boot-testjars-maven:0.0.4' - testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + implementation 'org.springframework.grpc:spring-grpc-spring-boot-starter' + implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' + implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'io.grpc:grpc-services' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.springframework.grpc:spring-grpc-test' + testImplementation 'org.springframework.experimental.boot:spring-boot-testjars-maven:0.0.4' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } test { - useJUnitPlatform() - testLogging.showStandardStreams = true - outputs.upToDateWhen { false } + useJUnitPlatform() + testLogging.showStandardStreams = true + outputs.upToDateWhen { false } +} + +sourceSets { + main { + proto { + srcDir 'src/main/protobuf' + } + } } protobuf { - protoc { - artifact = "com.google.protobuf:protoc:${dependencyManagement.importedProperties['protobuf-java.version']}" - } - plugins { - grpc { - artifact = "io.grpc:protoc-gen-grpc-java:${dependencyManagement.importedProperties['grpc.version']}" - } - } - generateProtoTasks { - all()*.plugins { - grpc { - option 'jakarta_omit' - option '@generated=omit' - } - } - } + protoc { + artifact = "com.google.protobuf:protoc:${dependencyManagement.importedProperties['protobuf-java.version']}" + } + plugins { + grpc { + artifact = "io.grpc:protoc-gen-grpc-java:${dependencyManagement.importedProperties['grpc.version']}" + } + } + generateProtoTasks { + all()*.plugins { + grpc { + option 'jakarta_omit' + option '@generated=omit' + } + } + } } diff --git a/samples/grpc-reactive/build.gradle b/samples/grpc-reactive/build.gradle index fbf9ca0..b705ce1 100644 --- a/samples/grpc-reactive/build.gradle +++ b/samples/grpc-reactive/build.gradle @@ -29,7 +29,7 @@ dependencyManagement { dependencies { implementation 'org.springframework.grpc:spring-grpc-spring-boot-starter' - implementation 'org.springframework.boot:spring-boot-starter-actuator' + implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'io.grpc:grpc-services' compileOnly 'javax.annotation:javax.annotation-api:1.3.2' implementation 'io.projectreactor:reactor-core' @@ -42,9 +42,17 @@ dependencies { } test { - useJUnitPlatform() - testLogging.showStandardStreams = true - outputs.upToDateWhen { false } + useJUnitPlatform() + testLogging.showStandardStreams = true + outputs.upToDateWhen { false } +} + +sourceSets { + main { + proto { + srcDir 'src/main/protobuf' + } + } } protobuf { diff --git a/samples/grpc-secure/build.gradle b/samples/grpc-secure/build.gradle index 7e933b2..89b60d6 100644 --- a/samples/grpc-secure/build.gradle +++ b/samples/grpc-secure/build.gradle @@ -1,62 +1,70 @@ plugins { - id 'java' - id 'org.springframework.boot' version '3.5.0' - id 'io.spring.dependency-management' version '1.1.6' - id 'org.graalvm.buildtools.native' version '0.10.3' - id 'com.google.protobuf' version '0.9.4' + id 'java' + id 'org.springframework.boot' version '3.5.0' + id 'io.spring.dependency-management' version '1.1.6' + id 'org.graalvm.buildtools.native' version '0.10.3' + id 'com.google.protobuf' version '0.9.4' } group = 'com.example' version = '0.9.0-SNAPSHOT' java { - toolchain { - languageVersion = JavaLanguageVersion.of(17) - } + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } } repositories { - mavenCentral() - maven { url 'https://repo.spring.io/milestone' } - maven { url 'https://repo.spring.io/snapshot' } + mavenCentral() + maven { url 'https://repo.spring.io/milestone' } + maven { url 'https://repo.spring.io/snapshot' } } dependencyManagement { - imports { - mavenBom 'org.springframework.grpc:spring-grpc-dependencies:0.9.0-SNAPSHOT' - } + imports { + mavenBom 'org.springframework.grpc:spring-grpc-dependencies:0.9.0-SNAPSHOT' + } } dependencies { - implementation 'org.springframework.grpc:spring-grpc-spring-boot-starter' - implementation 'org.springframework.boot:spring-boot-starter-security' - implementation 'io.grpc:grpc-services' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testImplementation 'org.springframework.grpc:spring-grpc-test' - testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + implementation 'org.springframework.grpc:spring-grpc-spring-boot-starter' + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'io.grpc:grpc-services' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.springframework.grpc:spring-grpc-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } test { - useJUnitPlatform() - testLogging.showStandardStreams = true - outputs.upToDateWhen { false } + useJUnitPlatform() + testLogging.showStandardStreams = true + outputs.upToDateWhen { false } +} + +sourceSets { + main { + proto { + srcDir 'src/main/protobuf' + } + } } protobuf { - protoc { - artifact = "com.google.protobuf:protoc:${dependencyManagement.importedProperties['protobuf-java.version']}" - } - plugins { - grpc { - artifact = "io.grpc:protoc-gen-grpc-java:${dependencyManagement.importedProperties['grpc.version']}" - } - } - generateProtoTasks { - all()*.plugins { - grpc { - option 'jakarta_omit' - option '@generated=omit' - } - } - } + protoc { + artifact = "com.google.protobuf:protoc:${dependencyManagement.importedProperties['protobuf-java.version']}" + } + plugins { + grpc { + artifact = "io.grpc:protoc-gen-grpc-java:${dependencyManagement.importedProperties['grpc.version']}" + } + } + generateProtoTasks { + all()*.plugins { + grpc { + option 'jakarta_omit' + option '@generated=omit' + } + } + } } diff --git a/samples/grpc-server-kotlin/build.gradle b/samples/grpc-server-kotlin/build.gradle index f4ecd82..908e059 100644 --- a/samples/grpc-server-kotlin/build.gradle +++ b/samples/grpc-server-kotlin/build.gradle @@ -53,6 +53,13 @@ test { outputs.upToDateWhen { false } } +sourceSets { + main { + proto { + srcDir 'src/main/protobuf' + } + } +} protobuf { protoc { diff --git a/samples/grpc-server-netty-shaded/build.gradle b/samples/grpc-server-netty-shaded/build.gradle index e43dd7f..727876f 100644 --- a/samples/grpc-server-netty-shaded/build.gradle +++ b/samples/grpc-server-netty-shaded/build.gradle @@ -42,9 +42,17 @@ dependencies { } test { - useJUnitPlatform() - testLogging.showStandardStreams = true - outputs.upToDateWhen { false } + useJUnitPlatform() + testLogging.showStandardStreams = true + outputs.upToDateWhen { false } +} + +sourceSets { + main { + proto { + srcDir 'src/main/protobuf' + } + } } protobuf { diff --git a/samples/grpc-server/build.gradle b/samples/grpc-server/build.gradle index 55655d3..ea34b41 100644 --- a/samples/grpc-server/build.gradle +++ b/samples/grpc-server/build.gradle @@ -29,7 +29,7 @@ dependencyManagement { dependencies { implementation 'org.springframework.grpc:spring-grpc-spring-boot-starter' - implementation 'org.springframework.boot:spring-boot-starter-actuator' + implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'io.grpc:grpc-services' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.grpc:spring-grpc-test' @@ -38,9 +38,17 @@ dependencies { } test { - useJUnitPlatform() - testLogging.showStandardStreams = true - outputs.upToDateWhen { false } + useJUnitPlatform() + testLogging.showStandardStreams = true + outputs.upToDateWhen { false } +} + +sourceSets { + main { + proto { + srcDir 'src/main/protobuf' + } + } } protobuf { diff --git a/samples/grpc-tomcat-secure/build.gradle b/samples/grpc-tomcat-secure/build.gradle index d9275cf..155a63c 100644 --- a/samples/grpc-tomcat-secure/build.gradle +++ b/samples/grpc-tomcat-secure/build.gradle @@ -31,16 +31,24 @@ dependencies { implementation 'org.springframework.grpc:spring-grpc-server-web-spring-boot-starter' implementation 'io.grpc:grpc-services' implementation 'org.springframework.boot:spring-boot-starter-actuator' - implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-security' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.grpc:spring-grpc-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } test { - useJUnitPlatform() - testLogging.showStandardStreams = true - outputs.upToDateWhen { false } + useJUnitPlatform() + testLogging.showStandardStreams = true + outputs.upToDateWhen { false } +} + +sourceSets { + main { + proto { + srcDir 'src/main/protobuf' + } + } } protobuf { diff --git a/samples/grpc-tomcat/build.gradle b/samples/grpc-tomcat/build.gradle index 81f0e12..9c563b0 100644 --- a/samples/grpc-tomcat/build.gradle +++ b/samples/grpc-tomcat/build.gradle @@ -38,9 +38,17 @@ dependencies { } test { - useJUnitPlatform() - testLogging.showStandardStreams = true - outputs.upToDateWhen { false } + useJUnitPlatform() + testLogging.showStandardStreams = true + outputs.upToDateWhen { false } +} + +sourceSets { + main { + proto { + srcDir 'src/main/protobuf' + } + } } protobuf { diff --git a/samples/grpc-webflux/build.gradle b/samples/grpc-webflux/build.gradle index ca49d69..3e8830f 100644 --- a/samples/grpc-webflux/build.gradle +++ b/samples/grpc-webflux/build.gradle @@ -37,9 +37,17 @@ dependencies { } test { - useJUnitPlatform() - testLogging.showStandardStreams = true - outputs.upToDateWhen { false } + useJUnitPlatform() + testLogging.showStandardStreams = true + outputs.upToDateWhen { false } +} + +sourceSets { + main { + proto { + srcDir 'src/main/protobuf' + } + } } protobuf { diff --git a/spring-grpc-docs/src/main/antora/modules/ROOT/pages/getting-started.adoc b/spring-grpc-docs/src/main/antora/modules/ROOT/pages/getting-started.adoc index fe4fc70..0b20afe 100644 --- a/spring-grpc-docs/src/main/antora/modules/ROOT/pages/getting-started.adoc +++ b/spring-grpc-docs/src/main/antora/modules/ROOT/pages/getting-started.adoc @@ -11,7 +11,7 @@ Generate the project and unzip the downloaded result. Open it in your IDE in the usual way. E.g. if you're using IntelliJ IDEA: `idea pom.xml`; or for VSCode `code .`. -Define a `.proto` service definition file `src/main/proto/hello.proto` with the following contents: +Define a `.proto` service definition file `src/main/protobuf/hello.proto` with the following contents: [source,proto] ----