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

社会主义新天地 提交于 2019-12-17 16:54:19

问题


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?


回答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.



来源:https://stackoverflow.com/questions/52044010/how-to-use-thrift-generator-as-maven-dependencyhow-to-avoid-reference-to-exe-f

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!