pom.xml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <parent>
  6. <artifactId>devops</artifactId>
  7. <groupId>cn.reghao.devops</groupId>
  8. <version>1.0.0</version>
  9. </parent>
  10. <modelVersion>4.0.0</modelVersion>
  11. <artifactId>agent</artifactId>
  12. <version>1.0.0</version>
  13. <properties>
  14. <project.build.outputDir>${project.parent.basedir}/bin/agent</project.build.outputDir>
  15. </properties>
  16. <dependencies>
  17. <dependency>
  18. <groupId>cn.reghao.devops</groupId>
  19. <artifactId>common</artifactId>
  20. <version>1.0.0-SNAPSHOT</version>
  21. </dependency>
  22. <dependency>
  23. <groupId>com.fasterxml.jackson.core</groupId>
  24. <artifactId>jackson-databind</artifactId>
  25. <version>2.15.2</version>
  26. </dependency>
  27. </dependencies>
  28. <build>
  29. <finalName>devops-${project.artifactId}</finalName>
  30. <resources>
  31. <resource>
  32. <directory>src/main/resources</directory>
  33. <filtering>true</filtering>
  34. <includes>
  35. <include>git.properties</include>
  36. <include>logback.xml</include>
  37. </includes>
  38. </resource>
  39. </resources>
  40. <plugins>
  41. <plugin>
  42. <groupId>org.apache.maven.plugins</groupId>
  43. <artifactId>maven-assembly-plugin</artifactId>
  44. <version>3.2.0</version>
  45. <configuration>
  46. <archive>
  47. <manifest>
  48. <mainClass>cn.reghao.devops.agent.AgentApp</mainClass>
  49. </manifest>
  50. </archive>
  51. <descriptorRefs>
  52. <descriptorRef>jar-with-dependencies</descriptorRef>
  53. </descriptorRefs>
  54. <!-- 不设置此属性则生成的 jar 包名字会带有 jar-with-dependencies -->
  55. <appendAssemblyId>false</appendAssemblyId>
  56. <outputDirectory>${project.build.outputDir}</outputDirectory>
  57. </configuration>
  58. <executions>
  59. <execution>
  60. <id>make-assembly</id>
  61. <phase>package</phase>
  62. <goals>
  63. <goal>single</goal>
  64. </goals>
  65. </execution>
  66. </executions>
  67. </plugin>
  68. <!--git-commit-id-plugin 插件,用于实现打包带git版本信息-->
  69. <plugin>
  70. <groupId>pl.project13.maven</groupId>
  71. <artifactId>git-commit-id-plugin</artifactId>
  72. <version>2.1.5</version>
  73. <executions>
  74. <execution>
  75. <goals>
  76. <goal>revision</goal>
  77. </goals>
  78. </execution>
  79. </executions>
  80. <configuration>
  81. <!--日期格式;默认值:dd.MM.yyyy '@' HH:mm:ss z;-->
  82. <dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
  83. <!--,构建过程中,是否打印详细信息;默认值:false;-->
  84. <verbose>true</verbose>
  85. <!-- ".git"文件路径;默认值:${project.basedir}/.git;
  86. 注意: 如果是多模块(多模块)项目,则需要修改到.git文件夹的目录-->
  87. <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
  88. <!--若项目打包类型为pom,是否取消构建;默认值:true;-->
  89. <skipPoms>false</skipPoms>
  90. <!--是否生成"git.properties"文件;默认值:false;-->
  91. <generateGitPropertiesFile>true</generateGitPropertiesFile>
  92. <!--指定"git.properties"文件的存放路径(相对于${project.basedir}的一个路径);
  93. 注意:该地址决定接口代码是否可以读取到git版本信息,请自行修改-->
  94. <generateGitPropertiesFilename>src/main/resources/git.properties</generateGitPropertiesFilename>
  95. <!--".git"文件夹未找到时,构建是否失败;若设置true,则构建失败;若设置false,则跳过执行该目标;默认值:true;-->
  96. <failOnNoGitDirectory>true</failOnNoGitDirectory>
  97. <!--git描述配置,可选;由JGit提供实现;-->
  98. <gitDescribe>
  99. <!--是否生成描述属性-->
  100. <skip>false</skip>
  101. <!--提交操作未发现tag时,仅打印提交操作ID,-->
  102. <always>false</always>
  103. <!--提交操作ID显式字符长度,最大值为:40;默认值:7;
  104. 0代表特殊意义;后面有解释;
  105. -->
  106. <abbrev>8</abbrev>
  107. <!--构建触发时,代码有修改时(即"dirty state"),添加指定后缀;默认值:"";-->
  108. <dirty>-dirty</dirty>
  109. <!--always print using the "tag-commits_from_tag-g_commit_id-maybe_dirty" format, even if "on" a tag.
  110. The distance will always be 0 if you're "on" the tag.
  111. -->
  112. <forceLongFormat>false</forceLongFormat>
  113. </gitDescribe>
  114. </configuration>
  115. </plugin>
  116. <!--apache maven插件,用于执行ant脚本函数-->
  117. <plugin>
  118. <artifactId>maven-antrun-plugin</artifactId>
  119. <version>1.8</version>
  120. <executions>
  121. <execution>
  122. <!--maven 插件生命周期,我试过用compile 发现打包以后没有git.properties,因为打包的时候,还没有生成
  123. 注意,这里改成 initialize 的话, 上面 git-commit-id-plugin 插件对应也该添加 phase 配置,并设置为 initialize
  124. 否则你生成的文件,写入的就不会对应的值,而是变量名-->
  125. <phase>initialize</phase>
  126. <goals>
  127. <goal>run</goal>
  128. </goals>
  129. <configuration>
  130. <tasks>
  131. <echo message="写入 git 版本信息"/>
  132. <!-- concat 常用于把一些信息写入文件,我这里用于把 git-commit-id-plugin 生成的git环境变量写入文件 -->
  133. <concat destfile="src/main/resources/git.properties">
  134. repo=${git.remote.origin.url}
  135. branch=${git.branch}
  136. commitId=${git.commit.id.abbrev}
  137. commitTime=${git.commit.time}
  138. buildTime=${git.build.time}
  139. </concat>
  140. </tasks>
  141. </configuration>
  142. </execution>
  143. </executions>
  144. </plugin>
  145. </plugins>
  146. </build>
  147. </project>