The project I am working on needs to use Google Protobuf for serialization, therefore a number of stub has to be generated before my code is built.
The command line arguments I use is:
protoc -I=src/proto --java_out=src/main/java src/proto/*.proto
This works fine in the console.
I now wants to use Maven exec plugin so that this manual process becomes part of the Maven build. The pom section I used is:
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.3.2</version>
<executions>
<execution>
<id>Google Protobuf Stub Generation</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>protoc</executable>
<commandlineArgs>-I=src/proto --java_out=src/main/java src/proto/*.proto</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
An error is given to complain there is no file called: src/proto/*.proto
However, it works fine if I remove the wildcard and specify a specific file, e.g.
<commandlineArgs>-I=src/proto --java_out=src/main/java src/proto/model.proto</commandlineArgs>
I think it is the wildcard * that cause the problem as Maven might have a different way to handle it.
My question is that how can I specify "All files with .proto extension in that folder" in Maven?
If you have bash, you can cheat and use 'bash' as your executable, '-c' as the first argument, and your full command as the second argument.
Essentially, the second argument will be ran in the shell, so wildcard(*) characters work and you generally get the same functionality as using the command line directly.
If you are calling the protoc command on a shell, the wildcard-operator is replaced by the shell with all matching files. protoc command itself is not able to handle the wildcard.
For example:
By calling "ls *.txt" on your shell, the ls command is not called with the argument "*.txt". The shell translates the command-call to "ls file1.txt file2.txt ..."
Solution: Create a command out of find xargs and protoc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With