• 【配置】Gradle下打包springboot项目,分离配置文件、依赖包


    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(' ')
        }
        }
    }
    
    
    • 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
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
  • 相关阅读:
    KMP 算法 + 详细笔记
    SpringMvc(一)-初识
    2022-11-18 mysql-filesort-分析
    Vue3 使用 Event Bus
    【Odoo】Odoo16-性能优化提升
    关于setInteval定时器在不同浏览器下表现差异
    Nacos集群搭建(图文教程)
    Arduino开发实例-DIY风速测量及显示
    inner join 、 left join 和 right join 区别
    首次使用服务器需要注意什么
  • 原文地址:https://blog.csdn.net/weixin_44155115/article/details/134512412