gpt4 book ai didi

java - Intellij中无法识别的 Protocol Buffer 导入

转载 作者:行者123 更新时间:2023-12-03 03:10:29 25 4
gpt4 key购买 nike

我正在尝试将一个 Protocol Buffer 消息导入到另一个 Protocol Buffer 消息中,但是无法识别导入。只要我不尝试将一个protobuf导入另一个protobuf,就会生成protobuf代码(在Java中),该代码将按预期编译并运行。
我正在使用:

  • Intellij Idea 2020 v1.3无限版
  • Protobuf编辑器插件:jvolkman/intellij-protobuf-editor(2020年4月)
  • Gradle

  • 我的gradle构建文件如下所示:
    plugins {
    id 'java'
    id 'com.google.protobuf' version "0.8.8"
    }

    group 'tech.tablesaw'
    version '1.0-SNAPSHOT'

    sourceCompatibility = 9.0

    def grpcVersion = '1.30.1' // CURRENT_GRPC_VERSION
    def protobufVersion = '3.12.0'
    def protocVersion = protobufVersion

    repositories {
    mavenCentral()
    }

    test {
    useJUnitPlatform()
    }

    dependencies {
    implementation "io.grpc:grpc-protobuf:${grpcVersion}"
    implementation "io.grpc:grpc-stub:${grpcVersion}"
    compileOnly "org.apache.tomcat:annotations-api:6.0.53"

    // advanced - need this for JsonFormat
    implementation "com.google.protobuf:protobuf-java-util:${protobufVersion}"

    runtimeOnly "io.grpc:grpc-netty-shaded:${grpcVersion}"
    testImplementation "io.grpc:grpc-testing:${grpcVersion}"

    compile group: 'tech.tablesaw', name: 'tablesaw-core', version: '0.38.1'
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.6.2'
    testImplementation "org.mockito:mockito-core:2.28.2"
    }

    protobuf {
    protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" }
    plugins {
    grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" }
    }
    generateProtoTasks {
    all()*.plugins { grpc {} }
    }
    }

    // Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code.
    sourceSets {
    main {
    java {
    srcDirs 'build/generated/source/proto/main/grpc'
    srcDirs 'build/generated/source/proto/main/java'
    }
    }
    }

    task TablesawServer(type: CreateStartScripts) {
    mainClassName = 'tech.tablesaw.service.TableServiceServer'
    applicationName = 'tablesaw-table-server'
    outputDir = new File(project.buildDir, 'tmp')
    }

    task TablesawClient(type: CreateStartScripts) {
    mainClassName = 'tech.tablesaw.service.TableServiceClient'
    applicationName = 'tablesaw-table-client'
    outputDir = new File(project.buildDir, 'tmp')
    }
    我的gradle信息看起来像这样:
    ------------------------------------------------------------
    Gradle 5.1.1
    ------------------------------------------------------------

    Build time: 2019-01-10 23:05:02 UTC
    Revision: 3c9abb645fb83932c44e8610642393ad62116807

    Kotlin DSL: 1.1.1
    Kotlin: 1.3.11
    Groovy: 2.5.4
    Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
    JVM: 9.0.4 (Oracle Corporation 9.0.4+11)
    OS: Mac OS X 10.13.5 x86_64
    这是一个protobuf示例。 column_type.proto的导入失败。
    syntax = "proto3";

    package tech.tablesaw.service.common;

    import "tech/tablesaw/service/common/column_type.proto";

    option java_multiple_files = true;
    option java_package = "tech.tablesaw.service.common";
    option java_outer_classname = "ColumnMetaProto";
    option objc_class_prefix = "TSW";

    // Proto file describing column metadata message.

    // A column metadata object
    message ColumnMetadata {

    string name = 1;
    int32 size = 2;
    ColumnTypeEnum.ColumnType column_type = 3;
    }

    这是我要导入的文件:
    syntax = "proto3";

    package tech.tablesaw.service.common;

    option java_multiple_files = true;
    option java_package = "tech.tablesaw.service.common";
    option java_outer_classname = "ColumnTypeEnum";
    option objc_class_prefix = "TSW";

    enum ColumnType {
    SHORT = 0;
    INTEGER = 1;
    LONG = 2;
    FLOAT = 3;
    BOOLEAN = 4;
    STRING = 5;
    DOUBLE = 6;
    LOCAL_DATE = 7;
    LOCAL_TIME = 8;
    LOCAL_DATE_TIME = 9;
    INSTANT = 10;
    TEXT = 11;
    SKIP = 12;
    }

    最后,这是protobuf在文件系统中的位置。
    src > main > java
    > proto > tech > tablesaw > service > common > column_metadata.proto
    > column_type.proto

    最佳答案

    看一看readme,它描述了如何添加其他路径。
    默认情况下,intellij-protobuf-editor使用项目配置的源根作为protobuf导入路径。如果这不正确,则可以在Settings > Languages & Frameworks > Protocol Buffers中覆盖这些路径。取消选中“自动配置”,然后添加所需的任何路径。对于您的情况,您将添加.../src/main/java/proto(其中...表示项目的基本路径是什么)。

    关于java - Intellij中无法识别的 Protocol Buffer 导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62837953/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com