Help us understand the problem. What is going on with this article?

gradleをつかって依存ライブラリを含む単一で実行可能なjarを生成する

More than 5 years have passed since last update.

バッチ処理をおこなう実行可能jarを生成する場合にはコマンドラインでいちいちクラスパスを設定するのは面倒ですし依存関係がかわるとバッチ処理コマンドも変更する必要が出てくるので管理が煩雑です。

gradleを利用してjarを生成する際に依存jar内のクラスも含めて一つのjarに入れればデプロイが格段に楽になります。

やり方は簡単。
build.gradleファイルのjarの設定に
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
を加えるだけでできます。

build.gradle
apply plugin: "java"
apply plugin: "maven"

def defaultEncoding = 'UTF-8'
[compileJava, compileTestJava]*.options*.encoding = defaultEncoding

sourceCompatibility = 1.7 
targetCompatibility = 1.7 
group = 'com.mychaelstyle.libs'
archivesBaseName = 'awstools' 
version = '0.1.0'

repositories {
  maven {
    url System.getenv("HOME") + "/.m2/repository"
  }
  mavenCentral()
}

dependencies {
  testCompile "junit:junit:4.11"
  compile 'javax.mail:mail:1.4'
  compile 'com.amazonaws:aws-java-sdk:1.6.4'
}

jar {
  manifest {
    attributes 'Implementation-Title': 'Mychael Style Tools', 'Implementation-Version': 1.0 
    attributes "Main-Class" : "com.mychaelstyle.tools.Main"
  }
  from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした