Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entry for spring-projects-experimental/spring-grpc #1673

Closed
mhalbritter opened this issue Dec 16, 2024 · 5 comments
Closed

Add entry for spring-projects-experimental/spring-grpc #1673

mhalbritter opened this issue Dec 16, 2024 · 5 comments
Assignees

Comments

@mhalbritter
Copy link
Contributor Author

mhalbritter commented Dec 16, 2024

For Gradle, we need to:

  • Add id 'com.google.protobuf' version '0.9.4' plugin.
  • Add https://repo.spring.io/milestone and/or https://repo.spring.io/snapshot repos
  • Do a mavenBom 'org.springframework.grpc:spring-grpc-dependencies:0.2.0' dependency import
  • Add implementation 'org.springframework.grpc:spring-grpc-spring-boot-starter'
  • Add implementation 'io.grpc:grpc-services'
  • Add testImplementation 'org.springframework.grpc:spring-grpc-test'
  • Configure the protobuf plugin:
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'
	    }
	}
    }
}

However, using dependencyManagement.importedProperties triggers spring-gradle-plugins/dependency-management-plugin#193. Maybe we can workaround by using a provider.

@dsyer
Copy link
Contributor

dsyer commented Dec 16, 2024

Only if actuator is selected, too?

That's not the determining factor. There are other services included (e.g. reflection service that is needed for grpcurl clients). So I would say make it unconditional (and user can opt out later).

@mhalbritter
Copy link
Contributor Author

mhalbritter commented Dec 16, 2024

If spring-projects-experimental/spring-grpc#79 is implemented, the Gradle configuration is simplified:

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc'
    }
    plugins {
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java'
        }
    }
    generateProtoTasks {
        all()*.plugins {
            grpc {
                option 'jakarta_omit'
            }
        }
    }
}

@mhalbritter
Copy link
Contributor Author

Here's the Kotlin DSL equivalent:

import com.google.protobuf.gradle.id

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc"
    }
    plugins {
        id("grpc") {
            artifact = "io.grpc:protoc-gen-grpc-java"
        }
    }
    generateProtoTasks {
        all().forEach { task ->
            task.plugins {
                id("grpc") {
                    option("jakarta_omit")
                }
            }
        }
    }
}

@mhalbritter
Copy link
Contributor Author

mhalbritter commented Dec 16, 2024

For Maven, we would need:

Two properties which are used for the protobuf-maven-plugin configuration

<protobuf-java.version>3.25.5</protobuf-java.version>
<grpc.version>1.63.2</grpc.version>
  • TODO: Is there a better way to handle this? It's very easy that those versions diverge from the versions of spring-grpc-dependencies.

Scope import spring-grpc-dependencies:

<dependency>
    <groupId>org.springframework.grpc</groupId>
    <artifactId>spring-grpc-dependencies</artifactId>
    <version>0.3.0-SNAPSHOT</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

Add those dependencies:

<dependency>
    <groupId>org.springframework.grpc</groupId>
    <artifactId>spring-grpc-spring-boot-starter</artifactId>
</dependency>
<dependency>
    <groupId>io.grpc</groupId>
    <artifactId>grpc-services</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.grpc</groupId>
    <artifactId>spring-grpc-test</artifactId>
    <scope>test</scope>
</dependency>

Add a build extension to get the architecture later needed to download protoc:

<build>
    <extensions>
        <extension>
            <groupId>kr.motd.maven</groupId>
            <artifactId>os-maven-plugin</artifactId>
            <version>1.7.1</version>
        </extension>
    </extensions>
// ...

Add protobuf-maven-plugin:

<plugin>
    <groupId>org.xolstice.maven.plugins</groupId>
    <artifactId>protobuf-maven-plugin</artifactId>
    <version>0.6.1</version>
    <configuration>
        <protocArtifact>com.google.protobuf:protoc:${protobuf-java.version}:exe:${os.detected.classifier}</protocArtifact>
        <pluginId>grpc-java</pluginId>
        <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
    </configuration>
    <executions>
        <execution>
            <configuration>
                <pluginParameter>
                    jakarta_omit
                </pluginParameter>
            </configuration>
            <goals>
                <goal>compile</goal>
                <goal>compile-custom</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Add spring-milestones and/or spring-snapshots repositories.

That would mean that start.spring.io needs to know the versions of those dependencies:

  • 3.25.5 for protobuf-java.version (maybe we can read that from spring-grpc-dependencies)
  • 1.63.2 for grpc.version (maybe we can read that from spring-grpc-dependencies)
  • 1.7.1 for os-maven-plugin
  • 0.6.1 for protobuf-maven-plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants