maven 配置protocol buffer

IDEA安装protocol buffer插件

Google Protobuf support for JetBrains

setings > plugins

配置pom



    4.0.0

    rrr
    test
    1.0-SNAPSHOT

    
        UTF-8
        1.19.0
        3.6.1
        3.6.1
        
        1.7
        1.7
    

    
        
            
                io.grpc
                grpc-bom
                ${grpc.version}
                pom
                import
            
        
    

    
        
            io.grpc
            grpc-netty-shaded
            runtime
        
        
            io.grpc
            grpc-protobuf
        
        
            io.grpc
            grpc-stub
        
        
            javax.annotation
            javax.annotation-api
            1.2
            provided 
        
        
            io.grpc
            grpc-testing
            test
        
        
            com.google.protobuf
            protobuf-java-util
            ${protobuf.version}
        
        
            junit
            junit
            4.12
            test
        
        
            org.mockito
            mockito-core
            1.9.5
            test
        
    

    
        
            
                kr.motd.maven
                os-maven-plugin
                1.5.0.Final
            
        
        
            
                org.xolstice.maven.plugins
                protobuf-maven-plugin
                0.6.1
                true
                
                    
                    ${project.basedir}/src/main/proto
                    
                    
                    ${project.build.sourceDirectory}
                    
                    false
                    
                    ${project.build.directory}/generated-sources/protobuf/java
                    
                    
                        com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}
                    
                
                
                    
                        
                            compile
                            test-compile
                        
                        
                        
                        
                        

                        
                    
                
            
        
    


编写proto

// Copyright 2015 The gRPC Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";

package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {
  }
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}

message Person {
  int32 id = 1;
  string name = 2;
  string email = 3;
}

生产java代码

  1. mvn compile
  2. 单机proto文件>右侧maven>Plugins>protobuf>双击protobuf:compile

你可能感兴趣的:(maven 配置protocol buffer)