0

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?

3
  • It looks like Thrift is something that you have to compile on your build machine, which means that the path to the executable is always going to be build dependent. That said, you could store that path in a property and define the property in a profile you store in settings.xml on the build machine.
    – Stephen B.
    Aug 27, 2018 at 17:23
  • @StephenB. , Could you elaborate? Aug 27, 2018 at 18:27
  • @Stephen B. actually I didn't build the Thrift locally - I just downloaded thrift-0.11.0.exe from the official site(thrift.apache.org/download) Aug 28, 2018 at 9:44

2 Answers 2

1

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.

1
0

You can avoid that if you can make sure the build server is installed with the docker runtime . You can then execute the thrift compiler in the form of a docker container which its image is already shared by people such as this one.

You can then use this fabric8io 's docker-maven-plugin to start a container to compile *.thrift in the generate-sources phase. For details , please refer to this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.