您的位置:首页 > 编程语言 > Java开发

基于eclipse+maven plugin开发grpc环境配置遇到的问题

2017-08-21 13:28 1666 查看
grpc开发使用proto3 IDL语言描述接口及消息通信数据模型,由该描述文件在编译期自动生成对应语言的代码,在eclipse IDE中使用maven项目结构开发时,需要maven插件的支持,具体配置如下:

<build>

    <extensions>

      <extension>

        <groupId>kr.motd.maven</groupId>

        <artifactId>os-maven-plugin</artifactId>

        <version>1.5.0.Final</version>

      </extension>

    </extensions>

    <plugins>

      <plugin>

        <groupId>org.xolstice.maven.plugins</groupId>

        <artifactId>protobuf-maven-plugin</artifactId>

        <version>0.5.0</version>

        <configuration>

          <protocArtifact>com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier}</protocArtifact>

          <pluginId>grpc-java</pluginId>

          <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>

        </configuration>

        <executions>

          <execution>

            <goals>

              <goal>compile</goal>

              <goal>compile-custom</goal>

            </goals>

          </execution>

        </executions>

      </plugin>

      <plugin>

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-enforcer-plugin</artifactId>

        <version>1.4.1</version>

        <executions>

          <execution>

            <id>enforce</id>

            <goals>

              <goal>enforce</goal>

            </goals>

            <configuration>

              <rules>

                <requireUpperBoundDeps/>

              </rules>

            </configuration>

          </execution>

        </executions>

      </plugin>

    </plugins>

  </build>

以上配置在编译过程中可能会报错:java.lang.NosuchMethodError:org.apache.maven.execution.MavenSession.getSessionRepository()方法找不到异常,在maven3.0以下版本中,maven-core包中的MavenSession类确实没有定义getSessionRepository()方法,导致排错时一直被maven版本问题误导。该错误其实是由于protobuf-maven-plugin插件的配置依赖os-maven-plugin插件提供相关环境变量引起的,os-maven-plugin插件的作用是在编译时确定当前执行编译的操作系统环境,提供对应的系统变量,如:${os.detected.name}
, ${os.detected.arch} , ${os.detected.version.*}
, ${os.detected.classifier} 等, 其中:${os.detected.classifier}
= ${os.detected.name}+${os.detected.arch}


上述错误主要是由于仅在项目的pom.xml中配置os-maven-plugin插件时,该插件jar包只会下载到本地maven仓库中,eclipse
IDE找不到os-maven-plugin插件所提供的变量,因此最终解决的办法是将本地下载的os-maven-plugin jar添加到${ECLIPSE_HOME}/plugins目录下,问题解决!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  grpc eclipse