Skip to content

Commit

Permalink
Introduce quarkus-grpc-kotlin extension
Browse files Browse the repository at this point in the history
This is automatically added by Quarkus during build time
if both the `quarkus-grpc` and `quarkus-kotlin` extensions
are present.
Currently, all the extension does is plug into the gRPC codegen
phase.

Fixes: quarkusio#46675
  • Loading branch information
geoand committed Mar 10, 2025
1 parent 58ff745 commit 5ff6f1f
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 12 deletions.
10 changes: 10 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2319,6 +2319,16 @@
<version>${project.version}</version>
<classifier>shaded</classifier>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-kotlin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-kotlin-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-websockets</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions devtools/bom-descriptor-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-kotlin</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hal</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-kotlin-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hal-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.quarkus.grpc.codegen;

import java.nio.file.Path;
import java.util.List;

import org.eclipse.microprofile.config.Config;

/**
* Simple SPI that allows code to add additional options to the gRPC code generation invocation
*/
public interface AdditionalOutputHandler {

/**
* Whether this handler should be invoked for the given context
*/
boolean supports(SupportsInput input);

/**
* Actually provide the additional options to be passed to the gRPC codegen
*/
HandleOutput handle(HandleInput input);

interface SupportsInput {

Config config();
}

interface HandleInput {

Path outDir();
}

interface HandleOutput {

List<String> additionalOptions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -67,11 +68,11 @@ public class GrpcCodeGen implements CodeGenProvider {

private static final String USE_ARG_FILE = "quarkus.generate-code.grpc.use-arg-file";

private static final String GENERATE_KOTLIN = "quarkus.generate-code.grpc.kotlin.generate";
private final Iterable<AdditionalOutputHandler> additionalOutputHandlers = ServiceLoader
.load(AdditionalOutputHandler.class);

private Executables executables;
private String input;
private boolean hasQuarkusKotlinDependency;

@Override
public String providerId() {
Expand Down Expand Up @@ -99,7 +100,6 @@ public Path getInputDirectory() {
@Override
public void init(ApplicationModel model, Map<String, String> properties) {
this.input = properties.get("quarkus.grpc.codegen.proto-directory");
this.hasQuarkusKotlinDependency = containsQuarkusKotlin(model.getDependencies());
}

@Override
Expand Down Expand Up @@ -167,8 +167,22 @@ public boolean trigger(CodeGenContext context) throws CodeGenException {
"--grpc_out=" + outDir,
"--java_out=" + outDir));

if (shouldGenerateKotlin(context.config())) {
command.add("--kotlin_out=" + outDir);
for (AdditionalOutputHandler handler : additionalOutputHandlers) {
if (handler.supports(new AdditionalOutputHandler.SupportsInput() {
@Override
public Config config() {
return context.config();
}
})) {
AdditionalOutputHandler.HandleOutput output = handler.handle(new AdditionalOutputHandler.HandleInput() {
@Override
public Path outDir() {
return outDir;
}
});
command.addAll(output.additionalOptions());
}

}

if (shouldGenerateDescriptorSet(context.config())) {
Expand Down Expand Up @@ -305,11 +319,6 @@ private boolean isGeneratingFromAppDependenciesEnabled(Config config) {
.filter(value -> !"none".equals(value)).isPresent();
}

private boolean shouldGenerateKotlin(Config config) {
return config.getOptionalValue(GENERATE_KOTLIN, Boolean.class).orElse(
hasQuarkusKotlinDependency);
}

private boolean shouldGenerateDescriptorSet(Config config) {
return config.getOptionalValue(GENERATE_DESCRIPTOR_SET, Boolean.class).orElse(FALSE);
}
Expand Down
5 changes: 5 additions & 0 deletions extensions/grpc/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-virtual-threads-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-kotlin-deployment</artifactId>
<optional>true</optional> <!-- conditional dependency -->
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
Expand Down
54 changes: 54 additions & 0 deletions extensions/grpc/kotlin/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-kotlin-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-grpc-kotlin-deployment</artifactId>
<name>Quarkus - gRPC - Kotlin - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-codegen</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-kotlin</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.quarkus.grpc.kotlin.deployment;

import java.util.List;

import io.quarkus.grpc.codegen.AdditionalOutputHandler;

public class KotlinOutputHandler implements AdditionalOutputHandler {

private static final String GENERATE_KOTLIN = "quarkus.generate-code.grpc.kotlin.generate";

@Override
public boolean supports(SupportsInput input) {
return input.config().getOptionalValue(GENERATE_KOTLIN, Boolean.class).orElse(true);
}

@Override
public HandleOutput handle(HandleInput input) {
return new HandleOutput() {
@Override
public List<String> additionalOptions() {
return List.of("--kotlin_out=" + input.outDir());
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.quarkus.grpc.kotlin.deployment.KotlinOutputHandler
21 changes: 21 additions & 0 deletions extensions/grpc/kotlin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-grpc-kotlin-parent</artifactId>
<name>Quarkus - gRPC - Kotlin</name>
<packaging>pom</packaging>

<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
58 changes: 58 additions & 0 deletions extensions/grpc/kotlin/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-kotlin-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-grpc-kotlin</artifactId>
<name>Quarkus - gRPC - Kotlin - Runtime</name>
<description>Provides Kotlin support for Quarkus gRPC</description>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-kotlin</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<configuration>
<dependencyCondition>
<artifact>io.quarkus:quarkus-kotlin</artifact>
</dependencyCondition>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
artifact: ${project.groupId}:${project.artifactId}:${project.version}
name: "gRPC Kotlin"
metadata:
unlisted: true
3 changes: 2 additions & 1 deletion extensions/grpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
<module>xds</module>
<module>inprocess</module>
<module>cli</module>
<module>kotlin</module>
</modules>
</project>
</project>
5 changes: 5 additions & 0 deletions extensions/grpc/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-virtual-threads</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-kotlin</artifactId>
<optional>true</optional> <!-- conditional dependency -->
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("io.quarkus:quarkus-arc")
implementation("io.quarkus:quarkus-grpc")
compileOnly("com.google.protobuf:protobuf-kotlin")

testImplementation("io.quarkus:quarkus-junit5")
testImplementation("io.rest-assured:rest-assured")
Expand Down

0 comments on commit 5ff6f1f

Please sign in to comment.