Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Build fails with validate.proto #70

Open
pouriapirz opened this issue Nov 27, 2023 · 1 comment
Open

[Bug] Build fails with validate.proto #70

pouriapirz opened this issue Nov 27, 2023 · 1 comment
Labels
Bug Something isn't working

Comments

@pouriapirz
Copy link

Description

I am trying to use proto validate files in my Java project by adding/importing them via protoc-jar-maven-plugin plugin with protobuf version of 3.24.4. However, the build fails when gettin to compiling validate.proto with the below error:

[ERROR] /Users/<full path to files>/src/main/protobuf/protobuf/third_party/buf/validate/validate.proto [41:0]: F1127 09:41:56.086052       1 file.cc:153] Check failed: CollectExtensions(*dynamic_file_proto, extensions) 
Find unknown fields in FileDescriptorProto when building buf/validate/validate.proto. It's likely that those fields are custom options, however, those options cannot be recognized in the builder pool. 
This normally should not happen. Please report a bug.
[ERROR] /Users/<full path to files>/src/main/protobuf/protobuf/third_party/buf/validate/validate.proto [0:0]: *** Check failure stack trace: ***
[...]

Steps to Reproduce

  1. Create a Java/Maven project and add expression.proto, validate.proto and private.proto under proto files.
  2. Modify pom.xml file and add protoc-jar-maven-plugin plugin with proper input and include directories to import above files.
  3. Try building the project via mvn clean package

Expected Behavior

Build passes by compiling above 3 files successfully.

Actual Behavior

Build fails with the error described in the "Description" section above.

Environment

  • Operating System: macOS
  • Version: Ventura 13.2
  • Protobuf Compiler & Version: 3.24.4
@pouriapirz pouriapirz added the Bug Something isn't working label Nov 27, 2023
@pouriapirz pouriapirz changed the title Build fails with validate.proto [Bug] Build fails with validate.proto Nov 27, 2023
@mohsenrezaeithe
Copy link

mohsenrezaeithe commented Nov 28, 2023

I was able to reproduce this as well, and it turned out to be a missing ProtoBuf dependency and additional configuration for the mentioned Maven plugin, protoc-jar-maven-plugin.

After some digging the error was due to the fact that required context in validate.proto is supplied by com.google.protobuf:protobuf-java in the Java land, and in my case this dependency was not provided by any of the other packages I was importing, and I had to add it to the list of dependencies (from com.google.protobuf:protobuf-bom):

<dependency>
    <groupId>com.google.protobuf</groupId>
    <artifactId>protobuf-java</artifactId>
</dependency>

Additionally, the Maven plugin configuration needs to add explicit imports for protoc to pickup the right generated sources:

<plugin>
    <groupId>com.github.os72</groupId>
    <artifactId>protoc-jar-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <includeMavenTypes>direct</includeMavenTypes>
                <includeStdTypes>true</includeStdTypes>
                <protocVersion>${protobuf.version}</protocVersion>
                <inputDirectories>
                    <inputDirectory>src/main/protobuf</inputDirectory>
                </inputDirectories>
                <includeDirectories>
                    <includeDirectory>src/main/protobuf</includeDirectory>
                    <includeDirectory>src/main/protobuf/protobuf/third_party</includeDirectory>
                </includeDirectories>
                <outputTargets>
                    <outputTarget>
                        <type>java</type>
                        <addSources>main</addSources>
                        <outputDirectory>${project.basedir}/src/main/java</outputDirectory>
                    </outputTarget>
                </outputTargets>
            </configuration>
        </execution>
    </executions>
</plugin>

This was confirmed with io.grpc:protoc-gen-grpc-java:1.58.0 and protoc version 3.24.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants