pom.xml 7.2 KB

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