gpt4 book ai didi

java - 如何使用thrift生成器作为maven依赖(如何避免引用.exe文件)?

转载 作者:行者123 更新时间:2023-12-02 10:52:39 25 4
gpt4 key购买 nike

我在 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>

工作正常,但我不喜欢在源代码中引用 .exe 文件:

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

是否可以使用maven依赖来代替?怎么办?

最佳答案

所以,我认为您问题的答案是,“不,实际上没有办法避免将可执行文件的路径传递给插件。”

我能建议的最接近的是这样的:

在你的 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>

然后,在构建用户的~/.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>

现在,您可以检查 pom.xml,其中没有任何特定于计算机的路径。为了执行构建,需要定义属性 myProps.thriftExec,因此每个开发人员/构建者都需要在自己的计算机上安装 thrift 并为自己定义该属性。这样,Mac 或 Linux 主机就不会在尝试查找 Windows 卷等时陷入困境。

请参阅Maven documentation有关配置文件的更多详细信息以及它们为什么方便。

关于java - 如何使用thrift生成器作为maven依赖(如何避免引用.exe文件)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52044010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com