Gradle如何打包可执行的jar文件

Spring Boot打包bootjar这样就可以了

1
2
3
jar {
from { configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
}

指定Main Class,我是用Kotlin,所以类名后面加Kt

1
2
3
4
5
6
7
8
9
10
jar {
from { configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'ltz.AppKt'
)
}
}

分享到