基于 Gradle 构建 spring-boot-thin-launcher

build.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
plugins {
id 'java'
id 'maven-publish'
id 'org.springframework.boot' version '3.3.1'
id 'io.spring.dependency-management' version '1.1.5'
id 'org.springframework.boot.experimental.thin-launcher' version '1.0.31.RELEASE'
}

bootJar {
archiveFileName = "${project.name}.jar"
}

thinJar {
archiveFileName = "${project.name}-thin.jar"
}

thinResolvePrepare {
delete file('thin')
into file('thin')
}

publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
}

generatePomFileForMavenPublication {
destination = file('pom.xml')
}

生成 pom.xml

1
./gradlew generatePomFileForMavenPublication

编译生成 thin jar 包

1
./gradlew clean thinResolvePrepare

缓存 maven 依赖

1
./mvnw dependency:resolve

生成 thin jar 依赖结构

1
java -Dthin.dryrun=true -Dthin.root=thin -Dthin.repo=https://maven.aliyun.com/repository/public -jar thin/${project.name}-thin.jar

可能需要的命令

1
2
3
rsync -avzh thin/repository/ server:/opt/project/repository/

scp thin/${project.name}-thin.jar server:/opt/project/${project.name}.jar