使用 Maven、Git:如何标记代码的最新版本?

发布于 2024-12-27 07:35:42 字数 180 浏览 1 评论 0原文

我正在使用 Maven 3.0.3 和 Git。我使用集成工具 (Bamboo) 将代码分支从 Git 检出到目录中。然后该工具使用 Maven 运行标准构建生命周期(编译、测试、部署)。我想要的是,如果我的 Maven 部署任务成功,我想标记在 Git 中签出的代码版本。我怎样才能从 Maven 做到这一点?我们非常感谢您提供的任何示例配置。

I'm using Maven 3.0.3 with Git. I use an integration tool (Bamboo) to check out a branch of code from Git into a directory. The tool then uses Maven run the standard build lifecycle (compile, test, deploy). What I want is that if my Maven deploy task succeeds, I want to tag the version of my code that is checked out in Git. How can I do this from Maven? Any sample configurations you can provide are greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

醉城メ夜风 2025-01-03 07:35:42

使用 Maven SCM 插件。请参阅高级功能中的标记功能,这应该是相关的。

现在,git 支持并不是现成的,因此您需要依赖 maven-scm-provider-gitexe。另外,为了克服 plexus 异常问题,您还需要添加对更高版本的 plexus 的依赖项。

这对我有用:

<project>
    <scm>
      <connection>scm:git:https://[email protected]/my-project.git</connection>
      <developerConnection>scm:git:https://[email protected]/my-project.git</developerConnection>
    </scm>
    <!-- snip -->
    <build>
      <plugins>
       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-scm-plugin</artifactId>
         <dependencies>
            <dependency>
               <groupId>org.codehaus.plexus</groupId>
               <artifactId>plexus-utils</artifactId>
               <version>2.1</version>
            </dependency>
            <dependency>
               <groupId>org.apache.maven.scm</groupId>
               <artifactId>maven-scm-provider-gitexe</artifactId>
               <version>1.2</version>
           </dependency>
         </dependencies>
        <version>1.0</version>
        <configuration>
          <tag>test</tag>
          <connectionType>connection</connectionType>
        </configuration>
        <executions>
          <execution>
          <id>tag</id>
          <phase>deploy</phase>
          <goals>
            <goal>tag</goal>
          </goals>
          </execution>
        </executions>
       </plugin>
     </plugins>
    </build>
    <!-- snip -->
</project>

Use Maven SCM plugin. See tag functionality in advanced features, which should be relevant.

Now, git support doesn't come out of the box, so you'll need a dependency to maven-scm-provider-gitexe. Also, to overcome plexus exception issue, you'll also need to add a dependency to a later version of plexus.

This is what worked for me:

<project>
    <scm>
      <connection>scm:git:https://[email protected]/my-project.git</connection>
      <developerConnection>scm:git:https://[email protected]/my-project.git</developerConnection>
    </scm>
    <!-- snip -->
    <build>
      <plugins>
       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-scm-plugin</artifactId>
         <dependencies>
            <dependency>
               <groupId>org.codehaus.plexus</groupId>
               <artifactId>plexus-utils</artifactId>
               <version>2.1</version>
            </dependency>
            <dependency>
               <groupId>org.apache.maven.scm</groupId>
               <artifactId>maven-scm-provider-gitexe</artifactId>
               <version>1.2</version>
           </dependency>
         </dependencies>
        <version>1.0</version>
        <configuration>
          <tag>test</tag>
          <connectionType>connection</connectionType>
        </configuration>
        <executions>
          <execution>
          <id>tag</id>
          <phase>deploy</phase>
          <goals>
            <goal>tag</goal>
          </goals>
          </execution>
        </executions>
       </plugin>
     </plugins>
    </build>
    <!-- snip -->
</project>
放肆 2025-01-03 07:35:42

maven-release-plugin 只需要声明 scm:

<scm>
    <url>https://github.com/username/repoName</url>
    <connection>scm:git:git://github.com/username/repoName.git</connection>
    <developerConnection>scm:git:[email protected]:username/repoName.git</developerConnection>
    <tag>HEAD</tag>
</scm>

生成 git ssh 密钥

https:// help.github.com/articles/generate-ssh-keys/

并运行 mvn release:prepare

更多来自 https://github.com/kevinsawicki/github-maven-example

maven-release-plugin needs only to declare the scm:

<scm>
    <url>https://github.com/username/repoName</url>
    <connection>scm:git:git://github.com/username/repoName.git</connection>
    <developerConnection>scm:git:[email protected]:username/repoName.git</developerConnection>
    <tag>HEAD</tag>
</scm>

generate git ssh keys

https://help.github.com/articles/generating-ssh-keys/

and run mvn release:prepare

more from https://github.com/kevinsawicki/github-maven-example

街角卖回忆 2025-01-03 07:35:42

maven-release-plugin 可以为您执行此操作 - 请参阅此处的示例: http://maven.apache.org/plugins/maven-release-plugin/examples/prepare-release.html

The maven-release-plugin can do this for you -- see an example here: http://maven.apache.org/plugins/maven-release-plugin/examples/prepare-release.html

明明#如月 2025-01-03 07:35:42

我推荐我参与的小型开源项目 - 它称为 Quicktag,可与几个 VCS 配合使用 - https://code.google.com/p/quicktag-maven-plugin。添加插件,它将生成带有包含构建信息的静态字段的 Java 类。

I recommend the small open source project I'm part of -it's called Quicktag and works with couple of VCSes - https://code.google.com/p/quicktag-maven-plugin. Add the plugin and it will generate Java class with static fields that contain build information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文