Как использовать Thrift Generator в качестве зависимости Maven (как избежать ссылки на файл .exe)? - PullRequest
0 голосов
/ 27 августа 2018

У меня есть следующий контент в 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-зависимость? как?

1 Ответ

0 голосов
/ 28 августа 2018

Итак, я думаю, что ответ на ваш вопрос: «Нет, на самом деле нет способа избежать доставки пути к исполняемому файлу для плагина».

Самое близкое, что я могу предложить, это что-то вроде этого:

В вашем 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 для получения более подробной информации о профилях и почему они удобны.

...