Jon*_*ito 9 scala protocol-buffers maven
我正在寻找一个包含所有这三件事的解决方案.到目前为止,我已经能够找到将在构建过程中从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>
Run Code Online (Sandbox Code Playgroud)
...有没有办法简单地让Maven构建在构建阶段将其作为命令行util启动?(希望生成源代码)我也发现了这一点,但我们不知道如何让它们很好地融合在一起: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>
Run Code Online (Sandbox Code Playgroud)
...我可以在构建期间生成源代码(在generate-sources阶段),但是由于某种原因运行exec插件后构建会立即停止.很近!如果有人能解决最后一个问题,这将解决.
已解决:maven exec 插件 java 目标不会分叉,因此 scalabuff 编译器中的 exit(0) 导致整个构建退出。还必须在生成源之前创建一个目录以使 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>
Run Code Online (Sandbox Code Playgroud)