前提
Spring Bootはまた別の手順がある。
もの
compileJava.dependsOn('clean')
task fatJarDependCopy(type: Copy, dependsOn: compileJava){
println "fatJarDependCopy called."
from {
configurations.runtimeClasspath
}
into "build/libs/lib"
}
task fatJar(type: Jar, dependsOn: "fatJarDependCopy") {
from sourceSets.main.output
def manifestClasspath = configurations.runtimeClasspath.collect { "lib/" + it.getName() }.join(' ')
manifest {
attributes 'Main-Class': "service.Test"
attributes 'Class-Path': manifestClasspath
}
}
archivesBaseName = "Test"
group = "sample"
version = '1.0.0'
compileJava.dependsOn('clean')
の働き
コンパイル前にクリーンを実行する。
fatJarDependCopyの働き
ランタイムクラスパスから依存関係をbuild/libs/lib
へコピー。
dependsOn: compileJava
はJar作成の事前条件。dependsOn
にタスクを指定することで自動実行する。
ここでは、事前にコンパイルをする。
fatJarの働き
- ソース指定
- マニフェストファイル用の
Class-Path
用変数の定義、指定 - マニフェストファイル用の
Main-Class
の指定
その他
変数 | 定義 |
---|---|
archiveBaseName | JarのBaseName |
group | installタスクのgroup名 |
version | Jarのサフィックス |
Jarの名称
[archiveBaseName]-[version].jar