0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

gradleで実行可能Jarを作る

Posted at

前提

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

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?