13
12

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 5 years have passed since last update.

Gradle で Fat Jar

Posted at

Gradle FatJar プラグインを使う。

build.gradle
buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'eu.appsatori:gradle-fatjar-plugin:0.3'
    }
}

apply plugin: 'eu.appsatori.fatjar'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.apache.commons:commons-lang3:3.4'
}

fatJar {
    baseName = 'fatjar'
    manifest {
        attributes('Main-Class': 'sample.fatjar.Main')
    }
}
Main.java
package sample.fatjar;

import org.apache.commons.lang3.StringUtils;

public class Main {

    public static void main(String... args) {
        System.out.println(StringUtils.join(args, " -> "));
    }
}
Jar作成
> gradle fatJar
実行
> java -jar build\libs\fatjar.jar hoge fuga piyo
hoge -> fuga -> piyo
Jarの中身
fatjar.jar
  |-META-INF/
  |  :
  |-org/apache/commons/lang3/
  |  :
  `-sample/fatjar/
     :

fatJar タスクは、 Jar タスクを継承しているので、 Jar と同じオプションを指定できる。

13
12
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
13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?