Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use wildcard in Maven exec plugin arguments

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?

like image 704
Kevin Avatar asked Jan 25 '15 10:01

Kevin


2 Answers

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.

like image 163
Ted Evingston Avatar answered Sep 22 '22 10:09

Ted Evingston


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.

like image 20
Martin Baumgartner Avatar answered Sep 19 '22 10:09

Martin Baumgartner