Maven Release Plugin and Git Tagging Style
Asked Answered
S

2

7

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.

Selfappointed answered 19/1, 2017 at 20:0 Comment(1)
Someone should not have to setup a release management system to learn a basic detail about its capabilities that is reasonably expected in documentation.Selfappointed
A
8

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

Antho answered 23/1, 2017 at 19:14 Comment(1)
I verified this by stepping backward through code. Maven Release Plugin uses Maven SCM Plugin uses Eclipse JGit. JGit only creates annotated tags. Then I was able to corroborate this in a forum a response from Robin Rosenberg, who is a committer to the JGit Project.Selfappointed
D
1

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.

Daley answered 17/8, 2023 at 18:13 Comment(1)
Git tag documentation also verifies that the git tag -F ... command implies -a (annotated). Thank you @Daley for an excellent response.Selfappointed

© 2022 - 2025 — McMap. All rights reserved.