编译 protoc-gen-grpc-java插件 的文档在:
https://github.com/grpc/grpc-java/tree/master/compiler
编译的步骤:
Change to the compiler directory:
$ cd $GRPC_JAVA_ROOT/compiler
To compile the plugin:
$ ../gradlew java_pluginExecutable
To test the plugin with the compiler:
$ ../gradlew java_pluginExecutable
编译过程中如果出现下面错误: fatal error: 'google/protobuf/io/zero_copy_stream.h' file not found。
是因为找不到这些头文件。找不到的原因如下:
Some versions of Mac OS X (e.g., 10.10) doesn't have /usr/local in the default search paths for header files and libraries.
It will fail the build of the codegen. To work around this, you will need to set environment variables:
参考: https://github.com/grpc/grpc-java/blob/master/COMPILING.md
错误的时候提示信息:
$ ../gradlew java_pluginExecutable
Download https://repo1.maven.org/maven2/org/mortbay/jetty/alpn/jetty-alpn-agent/2.0.2/jetty-alpn-agent-2.0.2.pom
Download https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-parent/25/jetty-parent-25.pom
Download https://repo1.maven.org/maven2/org/mortbay/jetty/alpn/jetty-alpn-agent/2.0.2/jetty-alpn-agent-2.0.2.jar
*** Building codegen requires Protobuf version 3.0.0-beta-2
*** Please refer to https://github.com/grpc/grpc-java/blob/master/COMPILING.md#how-to-build-code-generation-plugin
:grpc-compiler:compileJava_pluginExecutableJava_pluginCpp
/Users/ghj1976/project/github/grpc/grpc-java/compiler/src/java_plugin/cpp/java_generator.h:8:10: fatal error: 'google/protobuf/io/zero_copy_stream.h' file not found
#include <google/protobuf/io/zero_copy_stream.h>
^
1 error generated.
In file included from /Users/ghj1976/project/github/grpc/grpc-java/compiler/src/java_plugin/cpp/java_plugin.cpp:8:
/Users/ghj1976/project/github/grpc/grpc-java/compiler/src/java_plugin/cpp/java_generator.h:8:10: fatal error: 'google/protobuf/io/zero_copy_stream.h' file not found
#include <google/protobuf/io/zero_copy_stream.h>
^
1 error generated.
In file included from /Users/ghj1976/project/github/grpc/grpc-java/compiler/src/java_plugin/cpp/java_generator.cpp:1:
/Users/ghj1976/project/github/grpc/grpc-java/compiler/src/java_plugin/cpp/java_generator.h:8:10: fatal error: 'google/protobuf/io/zero_copy_stream.h' file not found
#include <google/protobuf/io/zero_copy_stream.h>
^
1 error generated.
:grpc-compiler:compileJava_pluginExecutableJava_pluginCpp FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':grpc-compiler:compileJava_pluginExecutableJava_pluginCpp'.
> Multiple build operations failed.
C++ compiler failed while compiling java_generator.h.
C++ compiler failed while compiling java_plugin.cpp.
C++ compiler failed while compiling java_generator.cpp.
See the complete log at: file:///Users/ghj1976/project/github/grpc/grpc-java/compiler/build/tmp/compileJava_pluginExecutableJava_pluginCpp/output.txt
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1 mins 24.831 secs
正确的时候的提示信息:
$ ../gradlew java_pluginExecutable
*** Building codegen requires Protobuf version 3.0.0-beta-2
*** Please refer to https://github.com/grpc/grpc-java/blob/master/COMPILING.md#how-to-build-code-generation-plugin
:grpc-compiler:compileJava_pluginExecutableJava_pluginCpp
:grpc-compiler:linkJava_pluginExecutable
:grpc-compiler:java_pluginExecutable
BUILD SUCCESSFUL
Total time: 14.818 secs
This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.11/userguide/gradle_daemon.html
localhost:compiler ghj1976$
$ ../gradlew java_pluginExecutable
Downloading https://services.gradle.org/distributions/gradle-2.13-bin.zip
.....................................................................................................................................................................................
Unzipping /Users/ghj1976/.gradle/wrapper/dists/gradle-2.13-bin/4xsgxlfjcxvrea7akf941nvc7/gradle-2.13-bin.zip to /Users/ghj1976/.gradle/wrapper/dists/gradle-2.13-bin/4xsgxlfjcxvrea7akf941nvc7
Set executable permissions for: /Users/ghj1976/.gradle/wrapper/dists/gradle-2.13-bin/4xsgxlfjcxvrea7akf941nvc7/gradle-2.13/bin/gradle
Download https://repo1.maven.org/maven2/com/google/protobuf/protobuf-gradle-plugin/0.7.7/protobuf-gradle-plugin-0.7.7.pom
Download https://repo1.maven.org/maven2/com/google/protobuf/protobuf-gradle-plugin/0.7.7/protobuf-gradle-plugin-0.7.7.jar
*** Building codegen requires Protobuf version 3.0.0-beta-2
*** Please refer to https://github.com/grpc/grpc-java/blob/master/COMPILING.md#how-to-build-code-generation-plugin
:grpc-compiler:compileJava_pluginExecutableJava_pluginCpp
:grpc-compiler:linkJava_pluginExecutable
:grpc-compiler:java_pluginExecutable
BUILD SUCCESSFUL
Total time: 4 mins 29.65 secs
This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.13/userguide/gradle_daemon.html
localhost:compiler ghj1976$
编译过程中如果出现下面错误: fatal error: 'google/protobuf/io/zero_copy_stream.h' file not found。
是因为找不到这些头文件。找不到的原因如下:
Some versions of Mac OS X (e.g., 10.10) doesn't have /usr/local in the default search paths for header files and libraries.
It will fail the build of the codegen. To work around this, you will need to set environment variables: