在Maven exec插件参数中使用通配符

Kev*_*vin 8 java protocol-buffers maven

我正在开发的项目需要使用Google Protobuf进行序列化,因此在构建代码之前必须生成许多存根.

我使用的命令行参数是:

protoc -I=src/proto --java_out=src/main/java src/proto/*.proto
Run Code Online (Sandbox Code Playgroud)

这在控制台中工作正常.

我现在想要使用Maven exec插件,以便这个手动过程成为Maven构建的一部分.我使用的pom部分是:

    <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>
Run Code Online (Sandbox Code Playgroud)

抱怨错误的是没有名为src/proto/*.proto的文件

但是,如果我删除通配符并指定特定文件,它可以正常工作,例如

<commandlineArgs>-I=src/proto --java_out=src/main/java src/proto/model.proto</commandlineArgs>
Run Code Online (Sandbox Code Playgroud)

我认为这是导致问题的通配符*因为Maven可能有不同的方式来处理它.

我的问题是如何在Maven中指定"该文件夹中包含.proto扩展名的所有文件"?

Mar*_*ner 1

如果您在 shell 上调用 protoc 命令,则通配符运算符将被具有所有匹配文件的 shell 替换。protoc 命令本身无法处理通配符。

例如:

通过在 shell 上调用“ls *.txt”,不会使用参数“*.txt”调用 ls 命令。shell 将命令调用转换为“ls file1.txt file2.txt ...”

解决方案:使用 find xargs 和 protoc 创建一个命令。