9

我正在寻找一个包含所有这三件事的解决方案。到目前为止,我已经能够找到可以在构建期间从 proto 文件生成 Java 代码的 Maven 插件,以及可以从 proto 文件生成 Scala 代码的命令行工具,但没有任何东西可以将所有内容混合在一起。

到目前为止,我发现的最有希望的是 ScalaBuff,事实上它存在于 Maven 存储库中。如果我因此将其添加为依赖项...

    <dependency>
        <groupId>net.sandrogrzicic</groupId>
        <artifactId>scalabuff-compiler_2.10</artifactId>
        <version>1.3.6</version>
    </dependency>
    <dependency>
        <groupId>net.sandrogrzicic</groupId>
        <artifactId>scalabuff-runtime_2.10</artifactId>
        <version>1.3.6</version>
    </dependency>

...有没有办法让 Maven 构建在构建阶段将其作为命令行工具启动?(希望生成源)我也找到了这个,但我不知道如何让这些很好地一起玩:Maven:http: //mojo.codehaus.org/exec-maven-plugin/

注意:我真的希望它是可移植的,而不是依赖于我本地盒子上安装的东西,但是非常欢迎黑客攻击(即添加一个 jar 或可执行文件到源代码控制)

提前致谢!

更新:

除了上述依赖之外,如果我添加以下...

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
            <execution>
                <id>protobuf-sources</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>java</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <mainClass>net.sandrogrzicic.scalabuff.compiler.ScalaBuff</mainClass>
            <arguments>
                <argument>--proto_path=src/main/protobuf</argument>
                <argument>--scala_out=target/generated-sources/scalabuff</argument>
            </arguments>
            <sourceRoot>target/generated-sources/scalabuff</sourceRoot>
        </configuration>
    </plugin>

...我可以在构建期间生成源代码(在 generate-sources 阶段),但是由于某种原因,在运行 exec 插件后构建会立即停止。很近!如果有人能解决最后一个问题,这将得到解决。

4

1 回答 1

1

已解决:maven exec 插件 java 目标不分叉,因此 scalabuff 编译器中的 exit(0) 导致整个构建退出。还必须在 generate-sources 之前创建一个目录以使 ScalaBuff 满意。使用 ScalaBuff 依赖项和以下插件确实有效!:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <configuration>
                <tasks>
                    <mkdir dir="target/generated-sources/scalabuff" />
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>protobuf-sources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>java</executable>
        <arguments>
          <argument>-classpath</argument>
          <!-- automatically creates the classpath using all project dependencies,
           also adding the project build directory -->
          <classpath/>
          <argument>net.sandrogrzicic.scalabuff.compiler.ScalaBuff</argument>
            <argument>--proto_path=src/main/protobuf</argument>
            <argument>--scala_out=target/generated-sources/scalabuff</argument>
        </arguments>
        <sourceRoot>target/generated-sources/scalabuff</sourceRoot>
    </configuration>
</plugin>
于 2017-02-08T15:42:36.937 回答