zhangkun83 | da3c3f8 | 2015-03-11 18:03:31 -0700 | [diff] [blame] | 1 | gRPC Java Codegen Plugin for Protobuf Compiler |
zhangkun83 | d54a463 | 2015-01-26 10:53:17 -0800 | [diff] [blame] | 2 | ============================================== |
| 3 | |
zhangkun83 | da3c3f8 | 2015-03-11 18:03:31 -0700 | [diff] [blame] | 4 | This generates the Java interfaces out of the service definition from a |
| 5 | `.proto` file. It works with the Protobuf Compiler (``protoc``). |
zhangkun83 | d54a463 | 2015-01-26 10:53:17 -0800 | [diff] [blame] | 6 | |
zhangkun83 | da3c3f8 | 2015-03-11 18:03:31 -0700 | [diff] [blame] | 7 | Normally you don't need to compile the codegen by yourself, since pre-compiled |
| 8 | binaries for common platforms are available on Maven Central. However, if the |
| 9 | pre-compiled binaries are not compatible with your system, you may want to |
| 10 | build your own codegen. |
zhangkun83 | d54a463 | 2015-01-26 10:53:17 -0800 | [diff] [blame] | 11 | |
zhangkun83 | da3c3f8 | 2015-03-11 18:03:31 -0700 | [diff] [blame] | 12 | ## System requirement |
zhangkun83 | d54a463 | 2015-01-26 10:53:17 -0800 | [diff] [blame] | 13 | |
zhangkun83 | da3c3f8 | 2015-03-11 18:03:31 -0700 | [diff] [blame] | 14 | * Linux, Mac OS X with Clang, or Windows with MSYS2 |
| 15 | * Java 7 or up |
Kun Zhang | e2ed2e8 | 2016-01-27 08:26:19 -0800 | [diff] [blame] | 16 | * [Protobuf](https://github.com/google/protobuf) 3.0.0-beta-2 or up |
zhangkun83 | da3c3f8 | 2015-03-11 18:03:31 -0700 | [diff] [blame] | 17 | |
| 18 | ## Compiling and testing the codegen |
zhangkun83 | d54a463 | 2015-01-26 10:53:17 -0800 | [diff] [blame] | 19 | Change to the `compiler` directory: |
| 20 | ``` |
| 21 | $ cd $GRPC_JAVA_ROOT/compiler |
| 22 | ``` |
| 23 | |
| 24 | To compile the plugin: |
| 25 | ``` |
Kun Zhang | 221c534 | 2015-04-29 18:16:15 -0700 | [diff] [blame] | 26 | $ ../gradlew java_pluginExecutable |
zhangkun83 | d54a463 | 2015-01-26 10:53:17 -0800 | [diff] [blame] | 27 | ``` |
| 28 | |
| 29 | To test the plugin with the compiler: |
| 30 | ``` |
zhangkun83 | da3c3f8 | 2015-03-11 18:03:31 -0700 | [diff] [blame] | 31 | $ ../gradlew test |
zhangkun83 | d54a463 | 2015-01-26 10:53:17 -0800 | [diff] [blame] | 32 | ``` |
| 33 | You will see a `PASS` if the test succeeds. |
| 34 | |
| 35 | To compile a proto file and generate Java interfaces out of the service definitions: |
| 36 | ``` |
Eric Anderson | 74490d5 | 2015-06-24 08:41:43 -0700 | [diff] [blame] | 37 | $ protoc --plugin=protoc-gen-grpc-java=build/binaries/java_pluginExecutable/protoc-gen-grpc-java \ |
| 38 | --grpc-java_out="$OUTPUT_FILE" --proto_path="$DIR_OF_PROTO_FILE" "$PROTO_FILE" |
zhangkun83 | d54a463 | 2015-01-26 10:53:17 -0800 | [diff] [blame] | 39 | ``` |
Xiao Hang | 6f0b21e | 2015-02-26 11:19:59 -0800 | [diff] [blame] | 40 | To generate Java interfaces with protobuf nano: |
| 41 | ``` |
Eric Anderson | 74490d5 | 2015-06-24 08:41:43 -0700 | [diff] [blame] | 42 | $ protoc --plugin=protoc-gen-grpc-java=build/binaries/java_pluginExecutable/protoc-gen-grpc-java \ |
Eric Anderson | 0a01b3c | 2016-03-29 16:16:21 -0700 | [diff] [blame] | 43 | --grpc-java_out=nano:"$OUTPUT_FILE" --proto_path="$DIR_OF_PROTO_FILE" "$PROTO_FILE" |
Xiao Hang | 6f0b21e | 2015-02-26 11:19:59 -0800 | [diff] [blame] | 44 | ``` |
zhangkun83 | da3c3f8 | 2015-03-11 18:03:31 -0700 | [diff] [blame] | 45 | |
| 46 | ## Installing the codegen to Maven local repository |
| 47 | This will compile a codegen and put it under your ``~/.m2/repository``. This |
| 48 | will make it available to any build tool that pulls codegens from Maven |
| 49 | repostiories. |
| 50 | ``` |
| 51 | $ ../gradlew install |
| 52 | ``` |
| 53 | |
nmittler | 483738e | 2015-06-08 14:32:37 -0700 | [diff] [blame] | 54 | ## Creating a release of GRPC Java |
| 55 | Please follow the instructions in ``RELEASING.md`` under the root directory for |
| 56 | details on how to create a new release. |