【问题标题】:ERROR: PROTOC FAILED: google/protobuf/wrappers.proto: File not found. (Error in Maven build)错误:协议失败:google/protobuf/wrappers.proto:找不到文件。 (Maven 构建中的错误)
【发布时间】:2021-01-24 15:37:07
【问题描述】:

我正在尝试使用以下插件构建 grpc 服务。好像插件无法使用 protoc 实用程序。

操作系统:MAC

Maven 版本:3.6.3

错误:

[ERROR] PROTOC FAILED: google/protobuf/wrappers.proto: File not found.
order-mgmt.proto: Import "google/protobuf/wrappers.proto" was not found or had errors.
order-mgmt.proto:7:16: "google.protobuf.StringValue" is not defined.

...
**[ERROR] Failed to execute goal org.xolstice.maven.plugins:protobuf-maven-plugin:0.6.1:compile (default) on project OrderManagement-gRPC: protoc did not exit cleanly. Review output for more information. -> [Help 1]**

我使用的插件是:

<plugin>
            <groupId>org.xolstice.maven.plugins</groupId>
            <artifactId>protobuf-maven-plugin</artifactId>
            <version>0.6.1</version>
            <configuration>
                <!--suppress UnresolvedMavenProperty -->
                <protocArtifact>com.google.protobuf:protoc:${protoc.version}: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>

【问题讨论】:

    标签: grpc-java protoc


    【解决方案1】:

    您缺少 protobuf-java 依赖项。

    <dependencies>
        <dependency>
          <groupId>com.google.protobuf</groupId>
          <artifactId>protobuf-java</artifactId>
          <version>3.5.1-1</version>
        </dependency>
        ...
      </dependencies>
    

    这是我使用插件的方式。

    <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.1</version>
          <extensions>true</extensions>
          <configuration>
            <protocArtifact>com.google.protobuf:protoc:3.5.1-1:exe:${os.detected.classifier}</protocArtifact>
          </configuration>
          <executions>
            <execution>
              <goals>
                <goal>compile</goal>
                <goal>test-compile</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
    

    然后使用mvn protobuf:compile 生成存根。参考来自插件仓库https://github.com/xolstice/protobuf-maven-plugin

    【讨论】:

    • 是的,我没有提供正确的 grpc 版本,这与我添加的依赖项不同步。基本上 grpc 和 protobuf 的依赖版本和使用的插件应该是同步的。所以最好在属性中使用,避免直接使用。谢谢 !!! :)
    【解决方案2】:

    提供 pom :

    记住 proto 和 grpc 版本。它们应该是同步的。最好在属性标签中声明它们,这样我们就不会提交任何版本不匹配。

    <?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">
    <modelVersion>4.0.0</modelVersion>
    
    <groupId>com.practice</groupId>
    <artifactId>OrderManagement-gRPC</artifactId>
    <version>1.0-SNAPSHOT</version>
    
    <properties>
    <grpc.version>1.35.0</grpc.version>
    <protoc.version>3.4.0</protoc.version>
        <encoding>UTF-8</encoding>
    </properties>
    
    
    <dependencies>
        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>${protoc.version}</version>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-netty-shaded</artifactId>
            <version>${grpc.version}</version>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-protobuf</artifactId>
            <version>${grpc.version}</version>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-stub</artifactId>
            <version>${grpc.version}</version>
        </dependency>
    </dependencies>
    
    
    <build>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.6.2</version>
            </extension>
        </extensions>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <echo>Displaying 1 environment variables</echo>
                                <echo>[Path] ${env.PATH}</echo>
                                <echo>[os.detected.classifier] ${os.detected.classifier}</echo>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.xolstice.maven.plugins</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
                <version>0.6.1</version>
                <configuration>
                    <!--suppress UnresolvedMavenProperty -->
                    <protocArtifact>com.google.protobuf:protoc:${protoc.version}: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-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
    
          
        </plugins>
    </build>
    

    【讨论】:

      【解决方案3】:

      我在没有“google/protobuf/wrappers.proto:找不到文件”的情况下遇到了这个问题。 这是因为我在没有管理员权限的情况下在 Windows 机器上运行了这个插件

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多