【问题标题】:Best way to integrate Git with Ant?将 Git 与 Ant 集成的最佳方式?
【发布时间】:2010-10-24 20:52:34
【问题描述】:

我正在寻找将 Git 与 Ant 集成的最佳方式。 Git 是否有广泛使用的 Ant 任务?有没有人有通过 Ant 使用 Git 的经验(例如专用任务、执行调用等)?

【问题讨论】:

标签: git ant integration


【解决方案1】:

Ant 支持exec command,您可以使用该exec command 将任何命令(包括Git)传递到命令行以执行。你总是可以依靠它。

【讨论】:

    【解决方案2】:

    看起来 Git 没有一组 Ant 任务。

    This blog 谈论使用 Git 的一些基本任务。

    【讨论】:

    【解决方案3】:

    这是通过 JGit 执行的 Git Ant 任务:http://aniszczyk.org/2011/05/12/git-ant-tasks-via-jgit/

    【讨论】:

      【解决方案4】:

      Look at JGit-Ant。不幸的是 jgit-ant 任务项目并没有所有主要的 git 操作,您可以找到更多信息 here

      对于 Java 开发人员:您可以使用 jgit 自己轻松编写 git-ant-commands,就像在 this examples 中一样。

      【讨论】:

      • 链接已损坏。
      【解决方案5】:

      看起来在 git 的 Ant 任务上完成了一些额外的非官方工作:

      我没有这方面的经验,但它们看起来比 tlrobinson 的更充实。

      【讨论】:

        【解决方案6】:

        结合使用 JGit 库和一些 <script language="javascript"> 代码(我使用的是 Rhino 库,但您同样可以使用 Groovy 等)。

        【讨论】:

          【解决方案7】:

          前段时间我没有成功地寻找集成 Git 和 Ant 的现成可用方法。我需要使用 Git 分支的名称创建构建的可能性。最后我得出了以下解决方案:

          摘自真实build.xml文件:

          <target name="-check-git-branch-name"
              if="using.git"
              >
              <exec executable="bash" logError="true" failonerror="true"
                  outputproperty="git-branch-name">
                  <arg value="./bin/git-branch-name.sh" />
              </exec>
          </target>
          

          文件./bin/git-branch-name.sh的全部内容

          #!/bin/bash
          
          # This script is the part of integration GIT to ANT. Once launched it 
          # should return the name of the current branch or the current commit (if 
          # GIT is the detached HEAD mode). Further the printed name is appended to 
          # the name of the resulting directory. To initialize this feature you need 
          # to run ANT with the option "-Dusing.git=". 
          
          exec 2>/dev/null
          
          git rev-parse --abbrev-ref HEAD | grep -v HEAD || git rev-parse HEAD
          

          调用类似于:

          ant TARGET options -Dusing.git=
          

          ${using.git} 被声明时,Ant 调用任务-check-git-branch-name 来收集分支的名称(或如果 Git 处于分离模式,则为提交的编号)并生成带有 Git 分支的附加名称的构建(或提交的 hnumber),例如build/TARGET-${git-branch-name}

          【讨论】:

            猜你喜欢
            • 2011-09-12
            • 2010-10-08
            • 2010-11-26
            • 2020-10-01
            • 2012-10-21
            • 2012-03-15
            • 1970-01-01
            • 2020-01-24
            • 1970-01-01
            相关资源
            最近更新 更多