Question

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 ?

Was it helpful?

Solution 3

Your protoc executable could not be executed on linux. You should download and compile protoc for linux and once you do it you will be able to use this maven plug-in as you are using it on windows.

You have detailed instruction for this here

OTHER TIPS

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>

A good cross-platform solution is to use the protoc binary artifacts available in Maven Central.

The simple configuration changes needed to your pom.xml are described in the com.google.protobuf.tools: maven-protoc-plugin documentation "Resolving Protoc Artifact From Maven Central Repo"

In case the link disappears, the salient part is:

<project>
  ...
  <build>
    <extensions>
      <extension>
        <groupId>kr.motd.maven</groupId>
        <artifactId>os-maven-plugin</artifactId>
        <version>1.3.0.Final</version>
      </extension>
    </extensions>
    <plugins>
      <plugin>
        <groupId>org.xolstice.maven.plugins</groupId>
        <artifactId>protobuf-maven-plugin</artifactId>
        <version>0.5.0</version>
        <extensions>true</extensions>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>test-compile</goal>
            </goals>
            <configuration>
              <protocArtifact>com.google.protobuf:protoc:2.6.1:exe:${os.detected.classifier}</protocArtifact>
            </configuration>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

You still need protoc but I think it is nicer to use a a protobuf maven plugin to compile proto files

I use this in my projects

<plugin>
	<groupId>com.github.igor-petruk.protobuf</groupId>
   		<artifactId>protobuf-maven-plugin</artifactId>
   			<executions>
   				<execution>
   					<configuration>
   						<cleanOutputFolder>false</cleanOutputFolder>
   					</configuration>
   					<goals>
   						<goal>run</goal>
   					</goals>
   				</execution>
   			</executions>
  </plugin>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top