Reputation: 4872
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.
Upvotes: 1
Views: 907
Reputation: 636
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
Upvotes: 3