ingyhere
ingyhere

Reputation: 13811

Maven Release Plugin and Git Tagging Style

Does the Maven Release Plugin perform lightweight or annotated tags in Git? (Also, does it support annotated tags if it is defaulting to lightweight tags?)

For instance, I can tag a project by hand using either:

git tag v1.0.0 # lightweight

or, alternately,

git tag -a v1.0.0 # annotated

These are very different types of tags. The first is a lightweight Git tag, and the second is an annotated Git tag.

(Note: I know that the release:prepare goal performs commits with POM changes, which in effect simulates an annotated tag because it ties the tag to a new, specific commit, but my question is whether an annotated tag is the result, anyway.)

Background: Maven 3.3.9 and Git 2.7.4 on a Mavenized Java project. Not easy to find this answer on Google or in SO.

UPDATE: Tags by the Maven Release Plugin are always annotated. There is no support for lightweight tags. See the answer below and my comments to corroborate it.

Upvotes: 7

Views: 4464

Answers (2)

mkjeldsen
mkjeldsen

Reputation: 2180

An annotated tag reports tag for git cat-file -t whereas a lightweight tag reports commit.

The Maven Release Plugin version 3.0.1 supports two Git provider implementations via the Maven SCM Plugin version 2.0.0:

This appears to have been true since the inception of Git support in maven-scm@fb97fde, 2008-04-05.

Though seemingly unspecified, the default SCM provider implementation appears to be the one that matches the SCM provider ID, in this case meaning git (not jgit). Running mvn release:prepare trivially demonstrates that git is the default provider implementation, in any case.

Specifically, the Release plugin runs the following commands by default:

~/foo $ mvn release:prepare --batch-mode
...
[INFO] 12/17 prepare:scm-tag
[INFO] Tagging release with the label foo-project-1.0...
[INFO] Executing: /bin/sh -c cd '/.../maven-multi-module-demo' && 'git' 'tag' '-F' '/tmp/maven-scm-2066945070.commit' 'foo-project-1.0'
[INFO] Working directory: /.../maven-multi-module-demo
[INFO] Executing: /bin/sh -c cd '/.../maven-multi-module-demo' && 'git' 'push' 'file:///tmp/tmp.HoDbTO8Iel' 'refs/tags/foo-project-1.0'

Note that git tag -F <file> implies the -a option; witness:

~/foo $ git cat-file -t foo-project-1.0
tag

Long ago, JGit supported only annotated tags. Since then, JGit has learned to support lightweight tags as well, but annotated tags remain the default and the Release plugin does not take the necessary steps to leverage lightweight tags so it is impossible to create lightweight tags. This is reasonably sensible: lightweight tags are inappropriate for this use case.

Upvotes: 1

Mark Taylor
Mark Taylor

Reputation: 128

While I didn't find documentation on this question (maybe it exists out there), I did a trial run. Create a local GIT repository with a simple POM and do a maven release:prepare. When I run git show $MYTAG on the resulting tag, git output contains "Tagger" data which suggests it is an annotated tag.

https://git-scm.com/book/en/v2/Git-Basics-Tagging

https://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html

Upvotes: 8

Related Questions