首页 > 解决方案 > 构建项目缺少依赖项后生成的 ProtoBuffer 文件

问题描述

我正在尝试在 grpc 的帮助下创建实现客户端-服务器通信

原型文件 -

syntax="proto3";

package com.project.grpc.roleservice;

message UserRequest {
    string userName=1;
}

message RoleReply {
    string userRole=1;
}

service UserRoleFromServer{
    rpc getRoleUser(stream UserRequest) returns (stream RoleReply);
}

摇篮构建 -

buildscript {
ext {
    springBootVersion = '2.0.4.RELEASE'
}
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    classpath("com.google.protobuf:protobuf-gradle-plugin:0.8.5")
    }
}


plugins {
id 'java'
}


apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.google.protobuf'

group 'com.project.grpc.roleservice'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

protobuf {
protoc {
    artifact = "com.google.protobuf:protoc:3.5.1-1"
}
plugins {
    grpc {
        artifact = 'io.grpc:protoc-gen-grpc-java:1.16.1'
    }
}
generateProtoTasks {
    all()*.plugins {
        grpc {}
    }
}
}

repositories {
    mavenCentral()
}

dependencies {

compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
compile( 'io.grpc:grpc-netty-shaded:1.16.1')
compile('io.grpc:grpc-protobuf:1.16.1')
compile('io.grpc:grpc-stub:1.16.1')
compile 'io.github.lognet:grpc-spring-boot-starter:3.0.0'
runtime('org.springframework.boot:spring-boot-devtools')
runtime('mysql:mysql-connector-java')
testCompile (group: 'junit', name: 'junit', version: '4.12')
}

构建项目后,所有文件都在构建文件夹中生成,并生成了一个 UserRoleFromServerGrpc,我想在我的服务器服务文件中扩展和实现它

但是 UserRoleFromServerGrpc 有很多错误,它要求以下依赖项

Streamobserver 需要 io.grpc:grpc-stub:1.16.1 ,grpc-core

将 io.grpc:grpc-stub:1.16.1 添加到类路径

但我已经在 gradle build 中定义了这些依赖项

如何解决此问题

IDE 截图

在此处输入图像描述

标签: javaspring-bootprotocol-buffersgrpc

解决方案


推荐阅读