在 gradle.build 文件中添加
// 将依赖包复制到lib目录
task copyJar(type: Copy) {
// 清除现有的lib目录
delete "$buildDir\\libs\\lib"
from configurations.runtime
// 部分版本需要使用下面这行
// from configurations.runtimeClasspath
into "$buildDir\\libs\\lib"
from configurations.compileClasspath
into "$buildDir\\libs\\lib"
}
// 拷贝配置文件
task copyConfigFile(type: Copy) {
// 清除现有的配置目录
delete "$buildDir\\libs\\config"
from('src/main/resources')
into 'build/libs/config'
}
// 配置bootJar进行打包
bootJar {
// jar包名称,默认是settings.gradle下的工程名 rootProject.name = 'alog-server'
archiveBaseName = 'alog-server'
// jar包版本号
archiveVersion = '0.0.1'
// 排除所有的jar
excludes = ["*.jar"]
// lib目录的清除和复制任务
dependsOn copyJar
// 配置目录的清除和复制任务
dependsOn copyConfigFile
// 指定依赖包的路径
manifest {
attributes "Manifest-Version": 1.0,
"Implementation-Title": "Halo Application",
"Implementation-Version": archiveVersion,
'Class-Path': configurations.compileClasspath.files.collect { "lib/$it.name" }.join(' ') + " " + configurations.runtimeClasspath.files.collect { "lib/$it.name" }.join(' ')
}
}
}