Skip to content

Commit 61f07be

Browse files
committed
Refactor gRPC plugin implementation
- Replace `VertxGrpcGeneratorImpl` with a new modular architecture for better maintainability. - Update Protobuf plugin configuration in `pom.xml` to reflect new plugin structure with `io.github.ascopes`. Signed-off-by: Daniel Fiala <danfiala23@gmail.com>
1 parent 56172de commit 61f07be

36 files changed

Lines changed: 2725 additions & 720 deletions

vertx-grpc-docs/src/main/asciidoc/plugin.adoc

Lines changed: 34 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -43,52 +43,34 @@ If you're using Apache Maven you need to add the plugin:
4343
[source,xml]
4444
----
4545
<plugin>
46-
<groupId>org.xolstice.maven.plugins</groupId>
47-
<artifactId>protobuf-maven-plugin</artifactId>
48-
<version>0.6.1</version>
49-
<configuration>
50-
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
51-
<pluginId>grpc-java</pluginId>
52-
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
53-
<protocPlugins>
54-
<protocPlugin>
55-
<id>vertx-grpc-protoc-plugin2</id>
56-
<groupId>io.vertx</groupId>
57-
<artifactId>vertx-grpc-protoc-plugin2</artifactId>
58-
<version>${stack.version}</version>
59-
<mainClass>io.vertx.grpc.plugin.VertxGrpcGenerator</mainClass>
60-
</protocPlugin>
61-
</protocPlugins>
62-
</configuration>
63-
<executions>
64-
<execution>
65-
<id>compile</id>
66-
<configuration>
67-
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
68-
<clearOutputDirectory>false</clearOutputDirectory>
69-
</configuration>
70-
<goals>
71-
<goal>compile</goal>
72-
<goal>compile-custom</goal>
73-
</goals>
74-
</execution>
75-
</executions>
46+
<groupId>io.github.ascopes</groupId>
47+
<artifactId>protobuf-maven-plugin</artifactId>
48+
<version>${ascopes.grpc.version}</version>
49+
<configuration>
50+
<protocVersion>${protobuf.version}</protocVersion>
51+
</configuration>
52+
<executions>
53+
<execution>
54+
<id>compile-java</id>
55+
<configuration>
56+
<jvmMavenPlugins>
57+
<jvmMavenPlugin>
58+
<groupId>io.vertx</groupId>
59+
<artifactId>vertx-grpc-protoc-plugin2</artifactId>
60+
<version>${vertx.version}</version>
61+
<mainClass>io.vertx.grpc.plugin.VertxGrpcGenerator</mainClass>
62+
<options>grpc-client=true,grpc-service=true,grpc-io=true</options>
63+
</jvmMavenPlugin>
64+
</jvmMavenPlugins>
65+
</configuration>
66+
</execution>
67+
</executions>
7668
</plugin>
7769
----
7870

79-
The plugin configuration includes:
80-
81-
1. **Protocol Buffer compiler artifact** (`protocArtifact`) - Required for compiling `.proto` files into Java classes
82-
2. **gRPC Java plugin** (`pluginId` and `pluginArtifact`) - Generates standard gRPC Java stubs, essential when using the `--grpc-io` option
83-
3. **Vert.x gRPC plugin** (`protocPlugins`) - Generates Vert.x-specific gRPC client and service classes
84-
4. **Output configuration** - Specifies where generated Java files will be placed (`src/main/java`)
85-
5. **Compilation goals** - Defines which Maven goals to execute (`compile` and `compile-custom`)
86-
87-
For more details, see the https://www.xolstice.org/protobuf-maven-plugin/[xolstice protobuf-maven-plugin documentation].
71+
This plugin uses `protocVersion` instead of platform-specific artifacts and takes care of downloading protoc based on your platform and version on its own.
8872

89-
The `${os.detected.classifier}` property is used to make the build OS independent, on OSX it is replaced
90-
by _osx-x86_64_ and so on. To use it you need to add the os-maven-plugin[https://github.com/trustin/os-maven-plugin]
91-
in the `build` section of your `pom.xml`:
73+
For more details, see the https://ascopes.github.io/protobuf-maven-plugin/[ascopes protobuf-maven-plugin documentation].
9274

9375
[source,xml]
9476
----
@@ -111,66 +93,23 @@ By default, the plugin generates both client and service files. If you need only
11193

11294
[source,xml]
11395
----
114-
<protocPlugin>
115-
<id>vertx-grpc-protoc-plugin2</id>
96+
<jvmMavenPlugin>
11697
<groupId>io.vertx</groupId>
11798
<artifactId>vertx-grpc-protoc-plugin2</artifactId>
118-
<version>${stack.version}</version>
99+
<version>${vertx.version}</version>
119100
<mainClass>io.vertx.grpc.plugin.VertxGrpcGenerator</mainClass>
120-
<args>
121-
<arg>--grpc-client</arg>
122-
</args>
123-
</protocPlugin>
124-
----
125-
126-
=== Alternative Plugin Configuration
127-
128-
Alternatively, you can use the newer `io.github.ascopes` protobuf plugin:
129-
130-
[source,xml]
101+
<options>grpc-client=true,grpc-service=true,grpc-io=true</options>
102+
</jvmMavenPlugin>
131103
----
132-
<plugin>
133-
<groupId>io.github.ascopes</groupId>
134-
<artifactId>protobuf-maven-plugin</artifactId>
135-
<version>${ascopes.grpc.version}</version>
136-
<configuration>
137-
<protocVersion>${protobuf.version}</protocVersion>
138-
</configuration>
139-
<executions>
140-
<execution>
141-
<id>compile-java</id>
142-
<configuration>
143-
<jvmMavenPlugins>
144-
<jvmMavenPlugin>
145-
<groupId>io.vertx</groupId>
146-
<artifactId>vertx-grpc-protoc-plugin2</artifactId>
147-
<version>${vertx.version}</version>
148-
<mainClass>io.vertx.grpc.plugin.VertxGrpcGenerator</mainClass>
149-
<jvmArgs>
150-
<jvmArg>--grpc-client=false</jvmArg>
151-
</jvmArgs>
152-
</jvmMavenPlugin>
153-
</jvmMavenPlugins>
154-
</configuration>
155-
</execution>
156-
</executions>
157-
</plugin>
158-
----
159-
160-
This plugin uses `protocVersion` instead of platform-specific artifacts and takes care of downloading protoc based on your platform and version on its own.
161-
162-
For more details, see the https://ascopes.github.io/protobuf-maven-plugin/[ascopes protobuf-maven-plugin documentation].
163104

164105
=== Arguments:
165106

166-
- _--grpc-client_: generate the client files
167-
- _--grpc-service_: generate the service files
168-
- _--grpc-io_: generate stub files compatible with `io.grpc:grpc-stub`, not generated by default. When using this option, you must also ensure the grpc-java plugin is configured (as shown in the Maven configuration above)
169-
- _--grpc-transcoding_: whether to generate transcoding options for methods with HTTP annotations
170-
- _--vertx-codegen_: whether to add Vert.x annotations to the generated classes (`@VertxGen`) By default, this is disabled
171-
- _--service-prefix_: generate service classes with a prefix. For example, if you set it to `MyService`, the generated service class will be `MyServiceGreeterService` instead of `GreeterService`.
172-
- _--help_: show help message
173-
- _--version_: show version information
107+
- _grpc-client_: generate the client files
108+
- _grpc-service_: generate the service files
109+
- _grpc-io_: generate stub files compatible with `io.grpc:grpc-stub`, not generated by default. When using this option, you must also ensure the grpc-java plugin is configured (as shown in the Maven configuration above)
110+
- _grpc-transcoding_: whether to generate transcoding options for methods with HTTP annotations
111+
- _vertx-codegen_: whether to add Vert.x annotations to the generated classes (`@VertxGen`) By default, this is disabled
112+
- _service-prefix_: generate service classes with a prefix. For example, if you set it to `MyService`, the generated service class will be `MyServiceGreeterService` instead of `GreeterService`.
174113

175114
If no specific generation options are provided, both client and service files will be generated by default. By default, all extensions (currently only 'http') are supported.
176115

vertx-grpc-it/pom.xml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,33 +114,34 @@
114114
</executions>
115115
</plugin>
116116
<plugin>
117-
<groupId>org.xolstice.maven.plugins</groupId>
117+
<groupId>io.github.ascopes</groupId>
118118
<artifactId>protobuf-maven-plugin</artifactId>
119+
<version>3.8.2</version>
119120
<configuration>
120-
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
121-
<pluginId>grpc-java</pluginId>
122-
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
123-
<protocPlugins>
124-
<protocPlugin>
125-
<id>vertx-grpc-protoc-plugin</id>
121+
<protocVersion>${protoc.version}</protocVersion>
122+
<binaryMavenPlugins>
123+
<binaryMavenPlugin>
124+
<groupId>io.grpc</groupId>
125+
<artifactId>protoc-gen-grpc-java</artifactId>
126+
<version>${grpc.version}</version>
127+
<options>@generated=omit</options>
128+
</binaryMavenPlugin>
129+
</binaryMavenPlugins>
130+
<jvmMavenPlugins>
131+
<jvmMavenPlugin>
126132
<groupId>io.vertx</groupId>
127133
<artifactId>vertx-grpc-protoc-plugin2</artifactId>
128134
<version>${project.version}</version>
129135
<mainClass>io.vertx.grpc.plugin.VertxGrpcGenerator</mainClass>
130-
<args>
131-
<arg>--grpc-client</arg>
132-
<arg>--grpc-service</arg>
133-
<arg>--grpc-io</arg>
134-
</args>
135-
</protocPlugin>
136-
</protocPlugins>
136+
<options>grpc-client=true,grpc-service=true,grpc-io=true</options>
137+
</jvmMavenPlugin>
138+
</jvmMavenPlugins>
137139
</configuration>
138140
<executions>
139141
<execution>
140142
<id>test-compile</id>
141143
<goals>
142-
<goal>test-compile</goal>
143-
<goal>test-compile-custom</goal>
144+
<goal>generate-test</goal>
144145
</goals>
145146
</execution>
146147
</executions>

vertx-grpc-protoc-plugin2/pom.xml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,9 @@
4040
<version>2.50.0</version>
4141
</dependency>
4242
<dependency>
43-
<groupId>com.salesforce.servicelibs</groupId>
44-
<artifactId>jprotoc</artifactId>
45-
<version>${jprotoc.version}</version>
46-
<exclusions>
47-
<exclusion>
48-
<groupId>javax.annotation</groupId>
49-
<artifactId>javax.annotation-api</artifactId>
50-
</exclusion>
51-
</exclusions>
52-
</dependency>
53-
<dependency>
54-
<groupId>info.picocli</groupId>
55-
<artifactId>picocli</artifactId>
56-
<version>4.7.5</version>
43+
<groupId>com.github.spullara.mustache.java</groupId>
44+
<artifactId>compiler</artifactId>
45+
<version>0.9.14</version>
5746
</dependency>
5847
</dependencies>
5948

0 commit comments

Comments
 (0)