[英]Maven thrift plugin - How can I include thrift definitions?
我目前正在使用maven-thrift-plugin在构建过程中自动生成jar和jsnode。 我可以成功地编译和部署定义,并在另一个项目中使用它们。 但是现在我需要让其他项目定义自己的节俭类型,其中包括其他定义,而我看不到如何以一种很好的自动化方式来实现这一目标。 例:
我有一个项目Foo。 它在它自己的git repo FooGitRepo中,并在com.example.foo中生成Maven工件FooMvnArtifact。 在Foo中,我有类似“ src / thrift / foo.thrift”的内容,它在com.example.foo包中定义了FooType。 到现在为止还挺好。
插件的pom如下所示:
<plugin>
<groupId>org.apache.thrift.tools</groupId>
<artifactId>maven-thrift-plugin</artifactId>
<version>0.1.11</version>
<configuration>
<thriftExecutable>${project.basedir}/compiler/thrift-0.9.1</thriftExecutable>
<thriftSourceRoot>${basedir}/src</thriftSourceRoot>
</configuration>
<executions>
<execution>
<id>generate-thrift-java</id>
<phase>generate-sources</phase>
<configuration>
<generator>java</generator>
<outputDirectory>
gen-java
</outputDirectory>
<compileOutput>true</compileOutput>
</configuration>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>generate-thrift-jsnode</id>
<phase>generate-sources</phase>
<configuration>
<generator>js:node</generator>
<outputDirectory>
gen-jsnode
</outputDirectory>
<compileOutput>false</compileOutput>
</configuration>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>thrift-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
这将产生适合于指定语言的工件输出。
在我的第二个项目中,在自己的git repo中的Bar拥有自己的maven repo,我在Java中使用Foo。 这很简单。 我只是将FooMvnArtifact放在Bar的pom的依赖项中。 然后,在Java代码中,我要做的就是import com.example.foo.FooType
。 但是现在我想添加一个Bar.thrift,其BarType包含一个FooType作为成员。 这意味着Bar.thrift需要include Foo.thrift
。 但这在Bar中是不可见的,因为Maven存储库仅包含节俭编译的特定于语言的工件,而不包含定义本身。
如何使Foo Maven存储库包含节俭定义本身? 如何使Bar以这种方式依赖于此定义,以便可以将其包含在其他旧式定义中? 如果将来我需要从不同项目导入多个CommonType.thrift,则最好以避免命名冲突的方式执行此操作。
将来在协议缓冲区的上下文中也可能会出现这种情况。 我希望解决方案将是相似的。
当maven-thrift-plugin执行generate-sources流程时,
1.将所有相关的节俭文件复制到一个临时目录
2.从项目的编译依赖工件(可以是jar,zip或其他类型的工件文件)中找到依赖的节俭文件。
您只需要将包含依赖项转换文件的项目添加到当前项目的编译依赖项中即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.