Question

I want to execute protoc (protobuffer compiler) from my maven file. I embeded an ant task in the pom.xml like the following

<executions>
  <execution>
      <id>generate-sources</id>
      <phase>generate-sources</phase>
      <configuration>
         <tasks>
           .... <!-- I have several of these blocks - how can I reduce them to one? -->
           <exec executable="protoc/protoc.exe">
              <arg value="--java_out=target/generated-sources"/>
              <arg value="src/main/protos/Proto1.proto"/>
              <arg value="--proto_path=src/main/protos"/>
           </exec>
           <exec executable="protoc/protoc.exe">
              <arg value="--java_out=target/generated-sources"/>
              <arg value="src/main/protos/Proto2.proto"/>
              <arg value="--proto_path=src/main/protos"/>
          </exec>
        .....
       </tasks>
       <sourceRoot>target/generated-sources</sourceRoot>
     </configuration>
     <goals>
       <goal>run</goal>
     </goals>
   </execution>

How can I define a loop or something so maven iterates all over the files in a directory?

I know there is a protobuffer maven plugin out there but I had to declare an external repository to use it and this is currently not an option.

Was it helpful?

Solution

The apply ant task should do you need. Replace the list of exec by :

<apply executable="protoc/protoc.exe" parallel="false">
  <arg value="--java_out=target/generated-sources"/>
  <srcfile/>
  <arg value="--proto_path=src/main/protos"/>
  <fileset dir="${basedir}/src/main/protos" includes="*.proto"/>
</apply>

http://ant.apache.org/manual/Tasks/apply.html

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