3

I am trying to automate the generation of source files from the .thrift files and later the packaging. As far as I know, the maven-thrift-plugin is restrictive in the sense that source and destination directories are fixed. Is there any way I can specify the source and destination directories? I could probably achieve this by using the maven-antrun-plugin but I don't want to pollute my pom unnecessarily if I don't have to.

Thanks.

Freewind
  • 193,756
  • 157
  • 432
  • 708
Kesh
  • 1,077
  • 2
  • 11
  • 20

2 Answers2

2

As far as I can see from the source (https://github.com/dtrott/maven-thrift-plugin/blob/master/src/main/java/org/apache/thrift/maven/ThriftCompileMojo.java) there are configuration properties that control this behaviour.

Try these properties, they should work:

  • thriftSourceRoot
  • thriftTestSourceRoot
  • outputDirectory

These props should be added to the <configuration> section along with <thriftExecutable>, etc:

<plugin>
    <groupId>org.apache.thrift.tools</groupId>
    <artifactId>maven-thrift-plugin</artifactId>
    <version>0.1.10</version>
    <configuration>
        <thriftExecutable>/usr/local/bin/thrift</thriftExecutable>
        <thriftSourceRoot>${basedir}/src/main/my_custom_thrift_root</thriftSourceRoot>
    </configuration>
    <executions>
    ...
</plugin>
Wildfire
  • 6,358
  • 2
  • 34
  • 50
  • Great! Thanks. This indeed generates the source files into the directory I specify. However, it creates – Kesh Feb 28 '14 at 15:22
  • Thanks! This indeed generates the source files into the directory I specify. However, it creates these files in a gen-java directory which I cannot seem to get rid of. Additionally, the plugin will force-clean the output directory which is also a bit of a problem for me as I have other helper classes in the directory and they get deleted as well. Is there any way I can avoid the force-cleanup? – Kesh Feb 28 '14 at 15:28
  • I don't think it's possible to get rid of `gen-java` (at least I couldn't do it even in command line). Speaking of force-clean: multiple java files might be generated from a single thrift source. So, the junk generated files will appear after every rename of a `struct`/`service` in thrift source. It's better to generate other files in different directories. – Wildfire Feb 28 '14 at 16:10
  • I feared as much. I'll see if I can use the `maven-antrun-plugin` after all. Thanks! – Kesh Feb 28 '14 at 16:48
0

I also ended up going the maven-antrun-plugin route, here is a functional example: https://github.com/cobbzilla/cobbzilla-wizard/tree/master/wizard-thrift

  • pom.xml uses maven-antrun-plugin to exec the thrift target in build.xml
  • build.xml does the thrift compilation and packaging.

Generated sources go back into the source tree; I don't like derived files polluting my upstream source control, so the generated files are under a thrift package, and the package directory is in a .gitignore file. A bit kludgy.

A better way I learned about since writing that code is to compile multiple java source directories in a single maven project, which would be cleaner.

cobbzilla
  • 1,920
  • 1
  • 16
  • 17