jannal commented on issue #413:
URL: https://github.com/apache/dubbo-samples/issues/413#issuecomment-1018152653


   gradle插件目前不支持mainClass方式,我的解决方式是在build.gradle同即目录下新建一个protobuf-pom.xml,然后mvn 
clean compile -f protobuf-pom.xml 来生成
   ```
   <?xml version="1.0" encoding="UTF-8"?>
   <project xmlns="http://maven.apache.org/POM/4.0.0";
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
       <groupId>cn.jannal.dubbo3</groupId>
       <version>1.0.0-SNAPSHOT</version>
       <modelVersion>4.0.0</modelVersion>
       <artifactId>dubbo-demo-protobuf</artifactId>
       <packaging>jar</packaging>
   
       <dependencyManagement>
           <dependencies>
               <dependency>
                   <groupId>org.apache.dubbo</groupId>
                   <artifactId>dubbo-bom</artifactId>
                   <version>3.0.5</version>
                   <type>pom</type>
                   <scope>import</scope>
               </dependency>
           </dependencies>
       </dependencyManagement>
   
   
       <dependencies>
   
           <dependency>
               <groupId>org.apache.dubbo</groupId>
               <artifactId>dubbo</artifactId>
           </dependency>
           <dependency>
               <groupId>io.grpc</groupId>
               <artifactId>grpc-protobuf</artifactId>
           </dependency>
   
           <dependency>
               <groupId>io.grpc</groupId>
               <artifactId>grpc-stub</artifactId>
           </dependency>
           <dependency>
               <groupId>com.google.protobuf</groupId>
               <artifactId>protobuf-java-util</artifactId>
           </dependency>
       </dependencies>
   
   
   
       <build>
           <extensions>
               <extension>
                   <groupId>kr.motd.maven</groupId>
                   <artifactId>os-maven-plugin</artifactId>
                   <version>1.7.0</version>
               </extension>
           </extensions>
           <plugins>
               <!--maven只负责生成protobuf代码,所以不能设置编译src/main/java-->
               <plugin>
                   <artifactId>maven-compiler-plugin</artifactId>
                   <version>3.3</version>
                   <configuration>
                       <source>1.8</source>
                       <target>1.8</target>
                       <!-- 不编译和复制类 -->
                       <excludes>
                           <exclude>**/*.java</exclude>
                       </excludes>
                   </configuration>
               </plugin>
               <!-- grpc代码生成插件 , protoc-gen-dubbo-java 支持 gRPC 和 Dubbo 两种协议-->
               <plugin>
                   <groupId>org.xolstice.maven.plugins</groupId>
                   <artifactId>protobuf-maven-plugin</artifactId>
                   <version>0.6.1</version>
                   <configuration>
                       <!--v3.19.1 有bug,isStringEmpty未公开-->
                       
<protocArtifact>com.google.protobuf:protoc:3.17.3:exe:${os.detected.classifier}</protocArtifact>
                       <pluginId>grpc-java</pluginId>
                       
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.31.1:exe:${os.detected.classifier}</pluginArtifact>
                       <outputDirectory>src/main/dubbo</outputDirectory>
                       <!--默认是grpc-->
                       <pluginParameter>grpc</pluginParameter>
                       <clearOutputDirectory>false</clearOutputDirectory>
                       <protocPlugins>
                           <protocPlugin>
                               <id>dubbo-grpc</id>
                               <groupId>org.apache.dubbo</groupId>
                               <artifactId>dubbo-compiler</artifactId>
                               <!--0.0.2和0.0.3都会报错Could not find resource 
DubboGrpcInterfaceStub.mustache-->
                               <version>0.0.1</version>
                               
<mainClass>org.apache.dubbo.gen.grpc.DubboGrpcGenerator</mainClass>
                           </protocPlugin>
                       </protocPlugins>
                   </configuration>
                   <executions>
                       <execution>
                           <goals>
                               <goal>compile</goal>
                               <goal>compile-custom</goal>
                               <goal>test-compile</goal>
                               <goal>test-compile-custom</goal>
                           </goals>
                       </execution>
                   </executions>
               </plugin>
           </plugins>
       </build>
   
   </project>
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to