简体   繁体   中英

Maven thrift plugin - How can I include thrift definitions?

I'm currently using the maven-thrift-plugin to generate jars and jsnode automatically during build. I'm successfully able to compile and deploy the definitions and use them in another project. But now I need to have that other project define its own thrift type that includes the other definitions, and I can't see how to accomplish this in a nice automated way. Example:

I have a project Foo. It's in it's own git repo FooGitRepo and produces maven artifact FooMvnArtifact in com.example.foo as well. In Foo I have something like "src/thrift/foo.thrift" which defines FooType in the com.example.foo package. So far so good.

The pom for the plugin looks like this:

       <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>

This produces the outputs in artifacts appropriate for the specified languages.

In my second project, Bar which is in its own git repo has its own maven repo I use Foo in java. This is very simple. I just put FooMvnArtifact in the dependency section of Bar's pom. Then in the java code all I have to do is import com.example.foo.FooType . But now I want to add a Bar.thrift with a BarType that contains a FooType as a member. That means that Bar.thrift needs to include Foo.thrift . But that isn't visible from Bar because the maven repo only contains the language-specific artifacts of the thrift compilation, not the definition itself.

How can I cause the Foo maven repo to contain the thrift definition itself? How can I get Bar to depend on this definition in such a way that I can include it in another thrift definition? Preferably I can do this in such a way as to avoid naming collisions if in the future I have multiple CommonType.thrift I need to import from different projects.

In the future this is likely going to come up in the context of protocol buffers as well. I would expect the solutions would be similar.

When the maven-thrift-plugin executes the generate-sources process,
1. it copies all dependent thrift files to a temporary directory
2. the dependent thrift files are found from the project's compile-dependency artifacts (which may be a jar, zip or other type artifact file)

You just need to add the project which contains the dependency thrift file into current project's compile dependency.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM