gradleメモ


Version
Gradle 6.5

Windows環境の人は最新化は再ダウンロードしましょう

gradlew 生成

gradle wrapper

gradlew によるバージョン更新

./gradlew wrapper --gradle-version=6.5

Executable Fat Jar(実行可能Jar)

implementationの依存関係もちゃんと取り込む。

Jar Task Document

task fatJar(type: Jar) {
    archiveBaseName = "アーカイブベース名"
//    archiveClassifier = 'アーカイブ分類名'

    from sourceSets.main.output

    dependsOn configurations.runtimeClasspath
    from {
        configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
    }
    manifest {
        attributes 'Main-Class': "メインクラス完全修飾名"
    }
}

依存ライブラリをフォルダにかき集める例

task fatJarDependCopy(type: Copy){
    println "fatJarDependCopy called."
    from {
        configurations.runtimeClasspath
    }
    into "build/libs/lib"
}
// サブプロくジェクトはJar化して調達すべし。
task fatJar(type: Jar) {
    dependsOn fatJarDependCopy
    archiveBaseName = "アーカイブベース名"
//    archiveClassifier = ''

    from sourceSets.main.output

    dependsOn configurations.runtimeClasspath
    def manifestClasspath = configurations.runtimeClasspath.collect { "lib/" + it.getName() }.join(' ')
    manifest {
        attributes 'Main-Class': "メインクラス名"
        attributes 'Class-Path': manifestClasspath
    }
}