gpt4 book ai didi

java - Protobuf配置Intellij Idea Plugin Gradle-kotlin-dsl kotlin

转载 作者:行者123 更新时间:2023-12-02 09:31:02 25 4
gpt4 key购买 nike

嘿,我想在 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 文件有一些无效的定义。

关于java - Protobuf配置Intellij Idea Plugin Gradle-kotlin-dsl kotlin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57979260/

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