Dave
Dave

Reputation: 19110

Using Maven, Git: How do I tag the latest version of my code?

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.

Upvotes: 18

Views: 38030

Answers (4)

eis
eis

Reputation: 53462

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>

Upvotes: 9

Edoardo
Edoardo

Reputation: 5442

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

Upvotes: 3

Marcin G&#243;rski
Marcin G&#243;rski

Reputation: 11

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.

Upvotes: -1

rayd
rayd

Reputation: 370

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

Upvotes: 2

Related Questions