javamaventhrift

How to use thrift generator as maven dependency(how to avoid reference to .exe file)?


I have following content in pom.xml:

...
<dependencies>
  ...
  <dependency>
            <groupId>org.apache.thrift</groupId>
            <artifactId>libthrift</artifactId>
            <version>0.11.0</version>
   </dependency>
</dependencies>
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.thrift.tools</groupId>
                <artifactId>maven-thrift-plugin</artifactId>
                <version>0.1.11</version>
                <configuration>
                    <thriftExecutable>D:/work/thrift-folder/thrift-0.11.0.exe</thriftExecutable>
                    <thriftSourceRoot>../thrift-files</thriftSourceRoot>
                    <generator>java</generator>
                </configuration>
                <executions>
                    <execution>
                        <id>thrift-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

It woks fine but I don't like to have reference to .exe file in my source code:

<thriftExecutable>D:/work/thrift-folder/thrift-0.11.0.exe</thriftExecutable>

Is it possible to use maven dependency instead? how?


Solution

  • So, I think the answer to your question is, "No, there's not really a way to avoid having the path to the executable delivered to the plugin."

    The closest I can suggest is something like this:

    In your pom.xml:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.thrift.tools</groupId>
                <artifactId>maven-thrift-plugin</artifactId>
                <version>0.1.11</version>
                <configuration>
                    <thriftExecutable>${myProps.thriftExec}</thriftExecutable>
                    <thriftSourceRoot>../thrift-files</thriftSourceRoot>
                    <generator>java</generator>
                </configuration>
                <executions>
                    <execution>
                        <id>thrift-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    

    And then, in the build user's ~/.m2/settings.xml:

    <profiles>
      <profile>
        <id>thrift-build</id>
          <properties>
              <myProps.thriftExec>D:/work/thrift-folder/thrift-0.11.0.exe</myProps.thriftExec>
          </properties>
      </profile>
    </profiles>
    

    Now, you can check in your pom.xml and it doesn't have any machine-specific paths in it. In order to execute the build, the property myProps.thriftExec needs to be defined, so each developer/builder will need to install thrift on their machine and define that property for themselves. That way a Mac or Linux host doesn't get stuck trying to find a Windows volume, etc.

    See the Maven documentation for more details on profiles and why they're handy.