通过将业务包和公共包分离,集中管理所有包,打包时只构建业务包减少项目包的大小和传输时间。
为了观测稳定性,暂通过环境区分,较为频繁的联调环境采用该方式,测试、预发、正式暂保持一体化打包方式不变。
注意:如果是第一次引入依赖(有依赖变动),则需要采用默认方式,先在本地构建打包再解压,将其中lib中的所有jar放于服务器上的lib目录中。(可通过步骤二增加一个默认环境的打包方式代替)
<build>
<plugins>
<plugin>
plugin>
plugins>
build>
<profiles>
<profile>
<id>defaultid>
<properties>
<project.env>defaultproject.env>
properties>
<activation>
<activeByDefault>trueactiveByDefault>
activation>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
profile>
<profile>
<id>devid>
<properties>
<project.env>devproject.env>
properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<configuration>
<mainClass>启动类路径mainClass>
<layout>ZIPlayout>
<includes>
<include>
直接隶属于项目的子包
include>
includes>
configuration>
<executions>
<execution>
<goals>
<goal>repackagegoal>
goals>
execution>
executions>
plugin>
plugins>
build>
profile>
profiles>
联调环境相比于默认环境需指定dev方式:clean install package -Pdev -Dmaven.test.skip=true
-Dloader.path=$BASE_PATH/lib
因是第一次构建需将项目依赖包都上传至公共管理路径lib,通过maven默认构建解压后上传

<build>
<plugins>
<plugin>
<groupId>org.mybatis.generatorgroupId>
<artifactId>mybatis-generator-maven-pluginartifactId>
<version>1.3.2version>
<configuration>
<configurationFile>${basedir}/src/main/resources/builder/generatorConfig.xml
configurationFile>
<overwrite>trueoverwrite>
<verbose>trueverbose>
configuration>
<dependencies>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>8.0.23version>
<scope>runtimescope>
dependency>
<dependency>
<groupId>com.baomidougroupId>
<artifactId>mybatis-plus-boot-starterartifactId>
<version>${mapper.version}version>
dependency>
dependencies>
plugin>
plugins>
build>
<profiles>
<profile>
<id>defaultid>
<properties>
<project.env>defaultproject.env>
properties>
<activation>
<activeByDefault>trueactiveByDefault>
activation>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
profile>
<profile>
<id>devid>
<properties>
<project.env>devproject.env>
properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<configuration>
<mainClass>com.runlion.hshb.erp.HshbErpWebApplicationmainClass>
<layout>ZIPlayout>
<includes>
<include>
<groupId>com.runlion.hshbgroupId>
<artifactId>hb-erp-apiartifactId>
include>
includes>
configuration>
<executions>
<execution>
<goals>
<goal>repackagegoal>
goals>
execution>
executions>
plugin>
plugins>
build>
profile>
profiles>
联调环境相比于默认环境需指定dev方式:clean install package -Pdev -Dmaven.test.skip=true

#!/usr/bin/env bash
source /etc/profile
source /app/hshb/erp/sh/constant.sh
BASE_PATH=/app/hshb/erp
PROJECT_NAME=hb-erp
JENKINS_JOB_NAME=hshb-ci-erp
PROFILE=$EVN_PROFILE
DEBUG_PORT=9065
TEMP_PATH=$BASE_PATH/artifacts/$PROJECT_NAME
JAR_NAME=$PROJECT_NAME.jar
echo "停止服务..."
PID=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
if [ -n "$PID" ]
then
echo "kill -9 pid:" $PID
kill -9 $PID
fi
echo "拷贝新jar到running目录"
cp $BASE_PATH/artifacts/$JENKINS_JOB_NAME/hb-erp-web-0.0.1-SNAPSHOT.jar $BASE_PATH/running/$JAR_NAME
echo "拷贝新jar的子jar到lib目录"
unzip -d $TEMP_PATH $BASE_PATH/artifacts/$JENKINS_JOB_NAME/hb-erp-web-0.0.1-SNAPSHOT.jar
mv $TEMP_PATH/BOOT-INF/lib/* $BASE_PATH/lib/
rm -rf $TEMP_PATH
echo "清理超过10天的日志文件..."
cd $BASE_PATH/logs
find $PROJECT_NAME/ -mtime +10 -name "*.log" -exec rm -rf {} \;
rm -rf $PROJECT_NAME-running.log
echo "启动服务 ..."
cd $BASE_PATH/running
nohup java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=$DEBUG_PORT,suspend=n -Xms768m -Xmx768m -jar -Dloader.path=$BASE_PATH/lib $JAR_NAME --spring.profiles.active=$PROFILE >> $BASE_PATH/logs/$PROJECT_NAME-running.log 2>&1 &
NEW_PID=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
echo "启动完成,当前服务PID=$NEW_PID"