获取Git提交信息,发版是需要Git的tag或者commitId

xml 复制代码
<build>
        <finalName>${project.artifactId}</finalName>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>${maven-source-plugin.version}</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- 获取Git提交信息,监控需要知道打包用的是哪个tag或者commit-->
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>4.0.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
                    <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>1.5.3</version> <!-- 请检查并使用最新版本 -->
                <executions>
                    <execution>
                        <id>replace-version-and-time</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                        <configuration>
                            <basedir>${project.build.directory}</basedir>
                            <includes>
                                <include>classes/jimi-build-info.properties</include>
<!--                                <include>${project.artifactId}/config/jimi-build-info.properties</include>-->
                            </includes>
                            <replacements>
                                <replacement>
                                    <!-- 替换为打包TAG,需要额外配置 -->
                                    <token>\$\{project\.version\}</token>
                                    <value>${git.tags}</value>
                                </replacement>
                                <replacement>
                                    <!-- 替换为打包时间,需要额外配置 -->
                                    <token>\$\{maven\.build\.timestamp\}\[UTC\]</token>
                                    <value>${maven.build.timestamp}[UTC]</value>
                                </replacement>
                            </replacements>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <parameters>true</parameters>
                    <verbose>true</verbose>
                    <showWarnings>true</showWarnings>
                    <fork>true</fork>
                    <meminitial>128m</meminitial>
                    <maxmem>1024m</maxmem>

                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <!-- 指明编译源代码时使用的字符编码, maven编译的时候默认使用的GBK编码, 通过encoding属性设置字符编码, 告诉maven这个项目使用UTF-8来编译 -->
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <compilerArgs>
                        <arg>-Xlint:unchecked</arg>
                    </compilerArgs>

                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${maven-failsafe-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <classesDirectory>${project.build.outputDirectory}</classesDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>${maven-jar-plugin.version}</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>${start-class}</mainClass>
                            <useUniqueVersions>false</useUniqueVersions>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                    <outputDirectory>${output.dir}/</outputDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>${maven-war-plugin.version}</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>${start-class}</mainClass>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>${maven-dependency-plugin.version}</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename>
                            <excludeScope>provided</excludeScope>
                            <outputDirectory>${output.dir}/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>${maven-resources-plugin.version}</version>
                <configuration>
                    <delimiters>
                        <delimiter>${resource.delimiter}</delimiter>
                    </delimiters>
                    <useDefaultDelimiters>false</useDefaultDelimiters>
                </configuration>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${output.dir}/config</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.build.directory}/classes</directory>
                                    <includes>
                                        <exclude>*.yml</exclude>
                                        <exclude>**/*.xml</exclude>
                                        <exclude>**/*.properties</exclude>
                                    </includes>
                                    <excludes>
                                        <exclude>git.properties</exclude>
                                    </excludes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${maven-spring-boot-plugin.version}</version>
                <configuration>
                    <mainClass>${start-class}</mainClass>
                    <layout>ZIP</layout>
                    <fork>true</fork>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
相关推荐
XIE3923 小时前
如何开发一个脚手架
前端·javascript·git·npm·node.js·github
stormsha6 小时前
如何在 .gitignore 中仅保留特定文件:以忽略文件夹中的所有文件为例
git
漆黑的莫莫8 小时前
经验笔记:git checkout 与 git switch
笔记·git
是Yu欸8 小时前
【Github】如何使用Git将本地项目上传到Github
人工智能·git·深度学习·github·论文笔记·cvpr
是垚不是土11 小时前
Ansible--自动化运维工具
运维·git·学习·自动化·云计算·ansible
originalHSL12 小时前
Load-Balanced-Online-OJ(负载均衡式在线OJ)
linux·c++·git·vscode·http·https·json
PBitW12 小时前
git 中容易遗忘的点!
前端·git·面试
与君共勉1213818 小时前
Jenkins-Gitlab 前端项目自动化部署
linux·服务器·git·gitlab·jenkins
元清加油1 天前
【Git】:Git基本操作
运维·git
夏沫的梦1 天前
Git命令使用与原理详解
git·gitlab·github