[英]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.