【问题标题】:How to enable Maven to see binary in $PATH?如何让 Maven 在 $PATH 中看到二进制文件?
【发布时间】:2013-04-01 11:18:54
【问题描述】:

我正在尝试添加 buildnumber maven 插件以包含来自 mercurial 的 hgchangeset。在终端中运行时,这对我很有用(我在 Mac OSX 上)。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.2</version>
    <executions>
      <execution>
        <phase>validate</phase>
        <goals>
          <goal>create</goal>
          <goal>hgchangeset</goal>  // The specific goal I'm interested in
          <goal>create-timestamp</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <doCheck>false</doCheck>
      <doUpdate>false</doUpdate>
      <revisionOnScmFailure>true</revisionOnScmFailure>
      <!-- format of the property 'buildNumber' -->
      <format>{0,date,MMdd-HHmm}</format>
      <items>
        <item>timestamp</item>
      </items>
    </configuration>
  </plugin>
</plugins>

但是,当在 Eclipse 和 Jenkins 中运行时,我得到了这个错误:

[INFO] EXECUTING: /bin/sh -c cd /Users/Shared/Jenkins/Home/jobs/proj/workspace && hg id -i
[ERROR] 
EXECUTION FAILED
  Execution of cmd : id failed with exit code: 127.
  Working directory was: 
    /Users/Shared/Jenkins/Home/jobs/proj/workspace
  Your Hg installation seems to be valid and complete.
    Hg version: NA (OK)

以用户 'jenkins' 身份登录该服务器,我可以执行:hg id -i 很好,我看到了正确的输出,因为hg 二进制文件在我的$PATH 上,并且在控制台中可以识别。

同样,Eclipse 提供相同的输出。我想这是因为在终端中,maven 构建可以在/usr/local/bin 中看到我的hg 二进制文件,但 Eclipse 和 Jenkins 不能。

有什么方法可以告诉 Maven 在那个位置使用hg?我不在乎它是否必须被硬编码,因为我们所有计算机上的二进制位置都是相同的。

提前致谢

回显 $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin

【问题讨论】:

    标签: maven mercurial maven-2 jenkins buildnumber-maven-plugin


    【解决方案1】:

    查看buildnumber-maven-plugin 的代码,似乎无法为hg 可执行文件提供前缀,或者覆盖已构建的实际命令行。

    因此,我建议修改 Jenkins 构建代理配置,以便调整用于定位 hgPATH。您可以按照Jenkins Distributed Builds setup 的说明执行此操作 - 通常(取决于您的构建从站的设置方式),您有几个选择:

    • 修改launch-slave shell 脚本
    • 为运行构建从属的用户修改.profile(或等效项)
    • 在 Jenkins UI 中修改代理配置,允许将环境变量传递给构建代理

    其中任何一个都应该允许您调整构建代理使用的PATH 的内容。

    祝你好运!

    【讨论】:

      【解决方案2】:

      我在 eclipse 和 maven 中遇到了同样的问题 - 虽然我的终端报告了一个包含二进制文件路径的 $PATH,但 eclipse 中的 maven-plugin 没有找到它。

      我很快就意识到了问题:Eclipse是从UI而不是终端启动的,所以它没有从终端继承环境变量,其中包括$PATH。这可以通过从终端启动eclipse来快速测试

      $./eclipse
      

      现在,这个 Eclipse 实例中的 maven 能够找到二进制文件了。

      为了在从 UI 启动时获取 eclipse 的路径,您还需要将路径添加到 /etc/paths

      【讨论】:

        猜你喜欢
        • 2018-12-21
        • 1970-01-01
        • 1970-01-01
        • 2015-04-16
        • 2018-06-06
        • 1970-01-01
        • 2017-06-12
        • 2010-12-18
        • 2018-08-17
        相关资源
        最近更新 更多