Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protocol buffers compiler maven plugin

I have protocol buffers compiler plugin configured in my POM that is executed whenever the project is built. This complier plugin works fine in windows but now I moved my project to an ubuntu PC & need to used a suitable alterntive for this.

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <id>compile-protoc</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <tasks>
                            <mkdir dir="src/main/resources/protocolBuffers/compiled" />
                            <path id="proto.path">
                                <fileset dir="src/main/proto">
                                    <include name="**/*.proto" />
                                </fileset>
                            </path>
                            <pathconvert pathsep=" " property="proto.files" refid="proto.path" />
                            <exec executable="src/main/resources/protocolBuffers/compiler/protoc" failonerror="true">
                                <arg value="--java_out=src/main/resources/" />
                                <arg value="-I${project.basedir}/" />
                                <arg line="${proto.files}"/>
                            </exec>
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

I see the following output when trying to build the project in Ubuntu netbeans

--- maven-antrun-plugin:1.3:run (compile-protoc) @ Px10App ---
Executing tasks
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 5.638s
Finished at: Tue Mar 25
Final Memory: 9M/105M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (compile-protoc) on project Px10App: An Ant BuildException has occured: Execute failed: java.io.IOException: Cannot run program "src/main/resources/protocolBuffers/compiler/protoc": error=2, No such file or directory -> [Help 1]

How to make compiler plugin work in Ubuntu netbeans ?

like image 358
Rajat Gupta Avatar asked Mar 24 '14 20:03

Rajat Gupta


1 Answers

This one comes with protoc built-in (it's originally based on igor-petruk/protobuf-maven-plugin, but it comes with protoc binaries bundled for Linux, Mac/OSX, and Windows). At runtime it detects the platform and executes the corresponding binary

https://github.com/os72/protoc-jar-maven-plugin

Here's an example:

<plugin>
    <groupId>com.github.os72</groupId>
    <artifactId>protoc-jar-maven-plugin</artifactId>
    <version>3.11.1</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <protocVersion>2.4.1</protocVersion>
                <inputDirectories>
                    <include>src/main/protobuf</include>
                </inputDirectories>
            </configuration>
        </execution>
    </executions>
</plugin>
like image 198
osuciu Avatar answered Sep 21 '22 22:09

osuciu