【问题标题】:import file in gRPC java project在 gRPC java 项目中导入文件
【发布时间】:2018-06-22 08:14:33
【问题描述】:

我正在尝试使用 gRPC 为 Google Actions 上的智能家居模块实现报告状态。但我不能为我的 *.proto 文件进行所有导入(如官方文档所述):https://developers.google.com/actions/smarthome/report-state
我做错了什么?
我的原型文件:

syntax = "proto3";

package google.home.graph.v1;

import "google/home/graph/v1/device.proto"; // --> file not found
...

build.gradle:

buildscript {
  repositories {
    mavenCentral()
    jcenter()
  }
  dependencies {
    classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE'
    classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
  }
}


group 'pro.company'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.google.protobuf'

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

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
  mavenCentral()
  jcenter()
}

jar {
  baseName = 'test'
  version = ''
}

springBoot {
  mainClass = "pro.foreway.Application"
  executable = true
}

dependencies {
  compile 'org.springframework.boot:spring-boot-starter-web'

  compile 'io.grpc:grpc-netty:1.12.0'
  compile 'io.grpc:grpc-protobuf:1.12.0'
  compile 'io.grpc:grpc-stub:1.12.0'

  compile 'com.google.api.grpc:googleapis-common-protos:0.0.3'
}


【问题讨论】:

    标签: gradle grpc-java google-smart-home


    【解决方案1】:

    您需要的所有 protos 都已添加到 googleapis repository,因此您应该可以将 device.proto 放入其中。我们还添加了一些与从主图中查询和同步数据相关的新 API以便更轻松地验证其拥有的数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-25
      • 2012-02-13
      • 1970-01-01
      • 1970-01-01
      • 2021-12-02
      • 1970-01-01
      相关资源
      最近更新 更多