SpringBoot+Gradle拆包配置

root项目build.gradle配置

    // 清除编译文件
    task clearProjectBuild(){
        delete "$buildDir\\libs"
    }

    // 将依赖包复制到lib目录
    task copyJar(type: Copy) {
        from configurations.runtimeClasspath
        into "$buildDir\\libs\\lib"
    }

    // 拷贝配置文件
    task copyConfigFile(type: Copy) {
        from('src\\main\\resources')
        into "$buildDir\\libs\\config"
        include "application*"
        include "bootstrap*"
    }

    // 拷贝k8s部署文件
    task copyK8sAndDockerFile(type: Copy){
        into "$buildDir\\libs"
        from("$rootDir\\k8s")
        include "compare.sh"
        include "dockerfile-"+project.name
    }

    //生成部署的文件
    task generateDeployFiles(){
        // 清除编译文件
        dependsOn clearProjectBuild
        // 将依赖包复制到lib目录
        dependsOn copyJar
        //将依赖包复制到lib目录
        dependsOn copyConfigFile
        //拷贝k8s部署文件
        dependsOn copyK8sAndDockerFile
    }

子项目build.gradle配置

// 配置bootJar进行打包--拆包
bootJar {
    // 排除所有的jar
    excludes = ["*.jar","bootstrap*"]
    //生成部署文件
    dependsOn generateDeployFiles

    // 指定依赖包的路径
    manifest {
        attributes "Manifest-Version": 1.0,
                'Class-Path': configurations.runtimeClasspath.files.collect { "lib/$it.name" }.join(' ')
    }
}

你可能感兴趣的:(gradle)