Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4230013
  • 博文数量: 447
  • 博客积分: 1241
  • 博客等级: 中尉
  • 技术积分: 5786
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-27 06:48
个人简介

读好书,交益友

文章分类

全部博文(447)

文章存档

2024年(1)

2023年(5)

2022年(29)

2021年(49)

2020年(16)

2019年(15)

2018年(23)

2017年(67)

2016年(42)

2015年(51)

2014年(57)

2013年(52)

2012年(35)

2011年(5)

分类: Java

2021-11-30 17:32:38

这个项目暂时这样用,马上就换成git了。
只需要修改pom文件即可实现
在pom中添加定义属性,用于规定相关信息的格式,可自行调整。

点击(此处)折叠或打开

  1. <properties>
  2.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  3.         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  4.         <java.version>1.8</java.version>
  5.         <mybatisplus.version>3.4.1</mybatisplus.version>
  6.         <springdoc.version>1.5.4</springdoc.version>
  7.         <maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
  8.         <buildTime>v.${project.version} build ${maven.build.timestamp}</buildTime>
  9.     </properties>
使用buildnumber-maven-plugin插件来帮助我们获取SVN版本号

点击(此处)折叠或打开

  1. <build>
  2.         <resources>
  3.             <resource>
  4.                 <directory>src/main/java</directory>
  5.                 <filtering>false</filtering>
  6.                 <includes>
  7.                     <include>**/*.xml</include>
  8.                 </includes>
  9.             </resource>
  10.             <resource>
  11.                 <directory>src/main/resources</directory>
  12.                 <filtering>true</filtering>
  13.                 <includes>
  14.                     <include>**/*.yml</include>
  15.                     <include>**/*.yaml</include>
  16.                     <include>**/*.properties</include>
  17.                     <include>**/*.xml</include>
  18.                 </includes>
  19.             </resource>
  20.             <resource>
  21.                 <directory>src/main/resources</directory>
  22.                 <filtering>false</filtering>
  23.                 <excludes>
  24.                     <exclude>**/*.yml</exclude>
  25.                     <exclude>**/*.yaml</exclude>
  26.                     <exclude>**/*.properties</exclude>
  27.                     <exclude>**/*.xml</exclude>
  28.                 </excludes>
  29.             </resource>
  30.             <resource>
  31.                 <directory>src/main/scripts</directory>
  32.                 <filtering>true</filtering>
  33.                 <includes>
  34.                     <include>**/*.sh</include>
  35.                 </includes>
  36.                 <targetPath>../scripts</targetPath>
  37.             </resource>
  38.         </resources>
  39.         <plugins>
  40.             <plugin>
  41.                 <groupId>org.springframework.boot</groupId>
  42.                 <artifactId>spring-boot-maven-plugin</artifactId>
  43.                 <configuration>
  44.                     <executable>true</executable>
  45.                     <mainClass>com.tfsec.tsa.Application</mainClass>
  46.                     <fork>true</fork>
  47.                     <excludes>
  48.                         <exclude>
  49.                             <groupId>org.springframework.boot</groupId>
  50.                             <artifactId>spring-boot-configuration-processor</artifactId>
  51.                         </exclude>
  52.                     </excludes>
  53.                 </configuration>
  54.             </plugin>
  55.             <plugin>
  56.                 <groupId>org.apache.maven.plugins</groupId>
  57.                 <artifactId>maven-jar-plugin</artifactId>
  58.                 <version>3.2.0</version>
  59.                 <configuration>
  60.                     <excludes>
  61.                         <exclude>**/scripts</exclude>
  62.                         <exclude>**/*.yml</exclude>
  63.                     </excludes>
  64.                      <archive>
  65.                         <manifestEntries>
  66.                             <buildTime>${buildTime}</buildTime>
  67.                             <SCM-Revision>${buildNumber}</SCM-Revision>
  68.                         </manifestEntries>
  69.                     </archive>
  70.                 </configuration>
  71.             </plugin>
  72.             <plugin>
  73.                 <groupId>org.apache.maven.plugins</groupId>
  74.                 <artifactId>maven-compiler-plugin</artifactId>
  75.                 <version>3.8.1</version>
  76.                 <configuration>
  77.                     <target>1.8</target>
  78.                     <source>1.8</source>
  79.                 </configuration>
  80.             </plugin>
  81.             <plugin>
  82.                 <artifactId>maven-assembly-plugin</artifactId>
  83.                 <executions>
  84.                     <execution>
  85.                         <phase>package</phase>
  86.                         <goals>
  87.                             <goal>single</goal>
  88.                         </goals>
  89.                         <configuration>
  90.                             <finalName>${project.artifactId}-${project.version}</finalName>
  91.                             <appendAssemblyId>false</appendAssemblyId>
  92.                             <descriptors>
  93.                                 <descriptor>src/assembly/assembly-descriptor.xml</descriptor>
  94.                             </descriptors>
  95.                         </configuration>
  96.                     </execution>
  97.                 </executions>
  98.             </plugin>
  99.             <plugin>
  100.                 <groupId>com.spotify</groupId>
  101.                 <artifactId>docker-maven-plugin</artifactId>
  102.                 <version>1.2.2</version>
  103.                 <configuration>
  104.                     <imageName>Tianyan/${project.artifactId}</imageName>
  105.                     <imageTags>
  106.                         <imageTag>${project.version}</imageTag>
  107.                         <imageTag>latest</imageTag>
  108.                     </imageTags>
  109.                     <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
  110.                     <serverId>docker-hub</serverId>
  111.                     <registryUrl>192.xxx.xx.130:5000</registryUrl>
  112.                     <resources>
  113.                         <resource>
  114.                             <targetPath>/</targetPath>
  115.                             <directory>${project.build.directory}</directory>
  116.                             <include>*.zip</include>
  117.                         </resource>
  118.                     </resources>
  119.                 </configuration>
  120.             </plugin>
  121.             <plugin>
  122.                 <artifactId>maven-resources-plugin</artifactId>
  123.                 <configuration>
  124.                     <encoding>utf-8</encoding>
  125.                     <useDefaultDelimiters>true</useDefaultDelimiters>
  126.                 </configuration>
  127.             </plugin>

  128.             <plugin>
  129.                 <groupId>org.codehaus.mojo</groupId>
  130.                 <artifactId>buildnumber-maven-plugin</artifactId>
  131.                 <version>1.4</version>
  132.                 <executions>
  133.                     <execution>
  134.                         <phase>validate</phase>
  135.                         <goals>
  136.                             <goal>create</goal>
  137.                         </goals>
  138.                     </execution>
  139.                 </executions>
  140.                 <configuration>
  141.                     <buildNumberPropertyName>buildNumber</buildNumberPropertyName>
  142.                     <revisionOnScmFailure>unknown</revisionOnScmFailure>
  143.                     <doCheck>false</doCheck>
  144.                     <doUpdate>false</doUpdate>
  145.                     <providerImplementations>
  146.                         <svn>javasvn</svn>
  147.                     </providerImplementations>
  148.                 </configuration>
  149.             </plugin>
  150.         </plugins>
  151.     </build>
添加一个虚拟的SVN服务器定义,否则上述插件不能正常工作。下面内容可直接使用,不需要改成实际的SVN地址。节点与、节点是相同等级,并列的。

点击(此处)折叠或打开

  1. <!-- 虚拟的SCM配置,为buildnumber插件服务 -->
  2. <scm>
  3.     <connection>scm:svn:http://127.0.0.1/dummy</connection>
  4.     <developerConnection>scm:svn:http://127.0.0.1/dummy</developerConnection>
  5.     <tag>HEAD</tag>
  6.     <url>http://127.0.0.1/dummy</url>
  7. </scm>
用压缩软件打开jar,查看\META-INF\MANIFEST.MF文件,应该可以看到版本号与时间信息

参考 

阅读(1077) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~