build.gradle 中按如下配置
apply plugin: 'java'
apply plugin: 'idea'
jar {
String someString = ''
configurations.runtime.each {
someString = someString + "lib/" + it.name + " ";
}
manifest {
attributes 'Main-Class': 'xxx'//这里填写入口函数所在类全限定名
attributes 'Class-Path': someString
}
}
//清除上次的编译过的文件
task clearPj(type: Delete) {
delete 'build', 'target'
}
//把JAR复制到目标目录
task release(type: Copy, dependsOn: [build]) {
from configurations.runtime
into 'build/libs/lib'
}