How to correctly compile Thrift using Maven
The org.apache.thrift.tools:maven-thrift-plugin is old and largely unmaintained (last updated 2013). It should not be used anymore. The correct plugin to use is org.apache.thrift:thrift-maven-plugin which was last updated in 2017.
The main problem with the maven-thrift-plugin and the thrift-maven-plugin is that it doesn't correctly integrate with the maven generate-sources command (at-least for Maven 3.8.4). The way to fix that is to change the generated sources to be placed in the src/main directory of the maven package. The `<generator>java</generator>` is to fix some of the backward incompatible changes on the thrift compiler's command line (usually shows up as an error: "unknown option java:hashcode").
Adding the following to your pom.xml will allow a process where the thrift files can be manually updated with a local command the rest of the compile is straightforward.
<plugin>
<!-- Note: trigger rebuild of java classes from thrift with
$ mvn thrift:compile
or alternatively
$ mvn org.apache.thrift:thrift-maven-plugin:compile
-->
<groupId>org.apache.thrift</groupId>
<artifactId>thrift-maven-plugin</artifactId>
<version>0.10.0</version>
<configuration>
<thriftSourceRoot>${basedir}/src/main/thrift</thriftSourceRoot>
<thriftExecutable>/usr/local/bin/thrift</thriftExecutable>
<generator>java</generator>
<outputDirectory>${basedir}/src/main/java</outputDirectory>
</configuration>
</plugin>
</plugins>
Comments
Post a Comment