繁体   English   中英

Protobuf配置Intellij Idea插件Gradle-kotlin-dsl kotlin

[英]Protobuf configuration Intellij Idea Plugin Gradle-kotlin-dsl kotlin

嘿,我想在intellij idea插件中设置protobuf作为其他protobuf服务器(用golang编写)的客户端。 那将是我对grpc的第一个Java方法。 我尝试使用kotlin类生成器,但是与这种方法相比,我获得的成功更少。

我的目标是:最佳情况:插件将允许将proto编译为kt文件非常好的情况:插件将将java文件输出到src / main / proto

现有代码结构:

└───src
    ├───main
    │   ├───kotlin
    │   │   └───pl
    │   │       └───dominikw
    │   │           ├───configuration
    │   │           ├───model
    │   │           ├───service
    │   │           │   └───impl
    │   │           └───ui
    │   ├───proto
    │   └───resources
    │       ├───icons
    │       └───META-INF
    └───test
        ├───kotlin
        └───resources

和Gradle kotlin dsl文件:

import com.google.protobuf.gradle.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "pl.dominikw"
version = "0.1.1"
val protobufVersion = "3.9.1"

buildscript {
    repositories {
        mavenCentral()
        maven("https://oss.sonatype.org/content/repositories/snapshots/")
        maven("https://dl.bintray.com/jetbrains/intellij-plugin-service")
    }
    dependencies {
        classpath("org.jetbrains.intellij.plugins:gradle-intellij-plugin:0.5.0-SNAPSHOT")
    }
}

plugins {
    id("org.jetbrains.intellij") version "0.4.10"
    id("com.google.protobuf") version "0.8.10"
    kotlin("jvm") version "1.3.50"
    java
    idea
}

repositories {
    mavenCentral()
    maven("https://dl.bintray.com/kittinunf/maven")
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.1")
    implementation("com.github.kittinunf.fuel", "fuel", "2.2.0")

    compile("com.google.protobuf:protobuf-java:$protobufVersion")
    compile("io.grpc:grpc-stub:1.15.1")
    compile("io.grpc:grpc-protobuf:1.15.1")
    if (JavaVersion.current().isJava9Compatible) {
        compile("javax.annotation:javax.annotation-api:1.3.2")
    }
//    protobuf(files("src/main/proto"))
//    "mainProto"(files("src/main/proto"))
    runtime("io.grpc:grpc-netty:1.14.0")
}

sourceSets {
    main {
        java.srcDir("src/main/kotlin")
        resources.srcDir("src/main/resources")
        proto.srcDir("src/main/proto")
    }
}

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
    version = "2019.2"
}
tasks.getByName<org.jetbrains.intellij.tasks.PatchPluginXmlTask>("patchPluginXml") {
    changeNotes(
        """
      Add change notes here.<br>
      <em>most HTML tags may be used</em>"""
    )
}

configure<org.jetbrains.intellij.IntelliJPluginExtension> {
    version = "2019.2"
    updateSinceUntilBuild = true
    pluginName = "Windchill-Plugin"
}
tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "1.8"
}

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:$protobufVersion"
    }
    plugins {
        id("grpc") {
            artifact = "io.grpc:protoc-gen-grpc-java:1.15.1"
        }
    }
    generateProtoTasks {
        ofSourceSet("main").forEach {
            it.plugins {
                id("grpc")
            }
        }
    }
}

错误代码如下:

7:17:20 PM: Executing task 'generateProto'...

> Task :extractIncludeProto UP-TO-DATE
> Task :extractProto UP-TO-DATE
> Task :generateProto FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generateProto'.
> protoc: stdout: . stderr: C:\Users\XXX\IdeaProjects\Windchill-Intellij-Plugin\build\extracted-protos\main\service.proto: Input is shadowed in the --proto_path by "C:/Users/XXX/IdeaProjects/Windchill-Intellij-Plugin/src/main/proto/service.proto".  Either use the latter file as your input or reorder the --proto_path so that the former file's location comes first.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
3 actionable tasks: 1 executed, 2 up-to-date
7:17:20 PM: Task execution finished 'generateProto'.

您的错误消息是:

  ...Input is shadowed in the --proto_path by "C:/Users/XXX/IdeaProjects/Windchill-Intellij-Plugin/src/main/proto/service.proto". 

proto文件夹中的.proto文件具有无效的某些定义。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM