プロトコル バッファ コンパイラを使用して、サービスの抽象クラスの代わりに Java インターフェイスを生成するにはどうすればよいですか?
現在、 .protoファイルを受け取り、インターフェイスの代わりにサービスの抽象クラスを生成する Gradle プラグインを使用しています。Java では複数のクラスを拡張できないため、これは問題になる可能性があります。
ドキュメントを調べた後、これまでのところ解決策や方法を見つけることができなかったので、何か助けていただければ幸いです。
私のbuild.gradleは次のようになります
apply plugin: 'java'
apply plugin: 'com.google.protobuf'
buildscript {
repositories {
mavenCentral()
}
dependencies {
// ASSUMES GRADLE 2.12 OR HIGHER. Use plugin version 0.7.5 with earlier
// gradle versions
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'
}
}
repositories {
mavenCentral()
mavenLocal()
}
// IMPORTANT: You probably want the non-SNAPSHOT version of gRPC. Make sure you
// are looking at a tagged version of the example and not "master"!
// Feel free to delete the comment at the next line. It is just for safely
// updating the version in our release process.
def grpcVersion = '1.0.0' // CURRENT_GRPC_VERSION
dependencies {
compile "io.grpc:grpc-netty:${grpcVersion}"
compile "io.grpc:grpc-protobuf:${grpcVersion}"
compile "io.grpc:grpc-stub:${grpcVersion}"
}
protobuf {
protoc {
// The version of protoc must match protobuf-java. If you don't depend on
// protobuf-java directly, you will be transitively depending on the
// protobuf-java version that grpc depends on.
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
all()*.plugins {
grpc {
// To generate deprecated interfaces and static bindService method,
// turn the enable_deprecated option to true below:
option 'enable_deprecated=false'
}
}
}
}
// Inform IntelliJ projects about the generated code.
apply plugin: 'idea'
idea {
module {
// Not using generatedSourceDirs because of
// https://discuss.gradle.org/t/support-for-intellij-2016/15294/8
sourceDirs += file("${projectDir}/build/generated/source/proto/main/java");
sourceDirs += file("${projectDir}/build/generated/source/proto/main/grpc");
}
廃止されたように見えるインターフェイスを生成していない理由を見つけたので、インターフェイスを生成する方法がわかりません。私のbuild.gradle option 'enable_deprecated=false'
を見ると、これをtrueにするとインターフェースが生成されますが、注釈は非推奨であると言っているので、インターフェースを生成する新しい方法が何であるかわかりません。抽象クラスではなくインターフェイスが必要です。