Git Commit ID Maven 插件使用教程

Git Commit ID Maven 插件使用教程

git-commit-id-maven-pluginMaven plugin which includes build-time git repository information into an POJO / *.properties). Make your apps tell you which version exactly they were built from! Priceless in large distributed deployments... :-)项目地址:https://gitcode.com/gh_mirrors/gi/git-commit-id-maven-plugin

1. 项目的目录结构及介绍

Git Commit ID Maven 插件的目录结构如下:

git-commit-id-maven-plugin/
├── docs/
│   └── using-the-plugin.md
├── src/
│   ├── main/
│   │   └── java/
│   │       └── pl/
│   │           └── project13/
│   │               └── maven/
│   │                   └── git/
│   │                       └── GitCommitIdPlugin.java
│   └── test/
│       └── java/
│           └── pl/
│               └── project13/
│                   └── maven/
│                       └── git/
│                           └── GitCommitIdPluginTest.java
├── pom.xml
└── README.md

目录结构介绍

  • docs/: 包含插件的使用文档,如 using-the-plugin.md
  • src/: 包含插件的源代码和测试代码。
    • main/java/: 插件的主要实现代码。
    • test/java/: 插件的测试代码。
  • pom.xml: Maven 项目的配置文件,定义了插件的依赖和构建配置。
  • README.md: 项目的介绍和使用说明。

2. 项目的启动文件介绍

项目的启动文件主要是 GitCommitIdPlugin.java,位于 src/main/java/pl/project13/maven/git/ 目录下。

GitCommitIdPlugin.java

这个文件是插件的核心实现,负责在 Maven 构建过程中获取 Git 提交信息,并将其注入到 Maven 项目的属性中。主要功能包括:

  • 获取 Git 提交 ID。
  • 获取 Git 提交的详细信息,如提交日期、作者等。
  • 将这些信息保存到指定的文件或 Maven 属性中。

3. 项目的配置文件介绍

项目的配置文件主要是 pom.xml,位于项目根目录下。

pom.xml

pom.xml 文件定义了插件的依赖、构建配置和插件的参数设置。以下是一些关键配置项:

<project>
    <build>
        <plugins>
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>4.0.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
                    <prefix>git</prefix>
                    <dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
                    <failOnNoGitDirectory>false</failOnNoGitDirectory>
                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

关键配置项介绍

  • dotGitDirectory: 指定 Git 仓库的目录,默认值为 ${project.basedir}/.git
  • prefix: 生成的 Git 属性的前缀,默认值为 git
  • dateFormat: 日期的格式,默认值为 yyyy-MM-dd'T'HH:mm:ssZ
  • failOnNoGitDirectory: 如果没有找到 Git 目录,是否构建失败,默认值为 false
  • generateGitPropertiesFile: 是否生成包含 Git 属性的文件,默认值为 true

通过这些配置项,可以灵活地控制插件的行为,以满足不同的构建需求。

git-commit-id-maven-pluginMaven plugin which includes build-time git repository information into an POJO / *.properties). Make your apps tell you which version exactly they were built from! Priceless in large distributed deployments... :-)项目地址:https://gitcode.com/gh_mirrors/gi/git-commit-id-maven-plugin

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

房迁伟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值