鉴于网上很多代码都是同一篇文章转载过来的基本验证无效,以下是经过项目测试后可用的方案
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| jar.doFirst { manifest { attributes 'Class-Path': configurations.compileClasspath.files.collect { "lib"+File.separator+"$it.name" }.join(' ') attributes 'Main-Class': 'com.halower.dynamicdb.DynamicDatasourceLab' } }
task thinJar(type: Copy) { def dir = new File( "$buildDir"+File.separator+"libs"); if(!dir.exists()) dir.mkdir() dir.eachDir{d -> d.delete()} from configurations.compileClasspath into "$buildDir"+File.separator+"libs"+File.separator+"lib" print('依赖包提取完成') }
jar.enabled = true bootJar.enabled = false
bootJar { dependsOn thinJar }
|