protoc jar maven plugin intellij not creating compiled proto files

2.4k views Asked by At

I am trying to use the protoc jar maven plugin in intelij. I've added this to my pom.xml:

        <plugin>
            <groupId>com.github.os72</groupId>
            <artifactId>protoc-jar-maven-plugin</artifactId>
            <version>3.1.0.2</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <includeDirectories>
                            <include>src/main/protobuf</include>
                        </includeDirectories>
                        <inputDirectories>
                            <include>src/main/protobuf</include>
                        </inputDirectories>
                    </configuration>
                </execution>
            </executions>
        </plugin>

I have a proto file located at src/main/protobuf. I also have this in my pom.xml:

    <dependency>
        <groupId>com.github.os72</groupId>
        <artifactId>protoc-jar</artifactId>
        <version>3.1.0.1</version>
    </dependency>

And here is the proto:

package stringtest;

message StringObject {
    repeated string string_one = 1;
    repeated string string_two = 2;
    repeated string string_three = 3;
}

However, whenever I right click on my module and click build, or if I go to the Build menu and hit Build project, I do not see any compiled protobuf files being generated. I also do not see any errors. Does anyone know what I am doing wrong?

2

There are 2 answers

0
Rob Sweny On

Make sure your .proto file is in your resources folder src/main/resources and your pom.xml can be anywhere within the src folder when you run maven install. You should see your files within your main java folder be generated.

0
krishna Ram On

We have used this below plugin

<plugin>
            <groupId>org.xolstice.maven.plugins</groupId>
            <artifactId>protobuf-maven-plugin</artifactId>
            <version>${protobuf.maven.plugin.version}</version>
            <configuration>
                <protocArtifact>com.google.protobuf:protoc:3.4.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>
                        <goal>compile-cpp</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Used these 2 dependencies it is compiling and creating objects from Protoc

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

    <dependency>
        <groupId>io.grpc</groupId>
        <artifactId>grpc-protobuf</artifactId>
        <version>${grpc.version}</version>
    </dependency>

Included everything from resources folder

 <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>