LoginSignup
1
1

More than 3 years have passed since last update.

gradle で 実行可能形式のjarを作るときpomがあるとzipで死ぬ場合の対応方法

Last updated at Posted at 2019-05-31

具体的には Google の API ライブラリを使ったときに起こった件。
よく検索するとでる方法は

from configurations.compile.collect {it.isDirectory() ? it : zipTree(it)}

方法なんですが、pomが入ってると死ぬんです。

15:44:57: Executing task 'jar'...

> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :jar FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':jar'.
> Could not expand ZIP '/xxxxx/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-ri/2.3.2/f37875be0bc7d265b5bbb08eb55b2345c27e67aa/jaxb-ri-2.3.2.pom'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 22s
3 actionable tasks: 1 executed, 2 up-to-date
Cause: archive is not a ZIP archive
15:45:21: Task execution finished 'jar'.

書いてるメッセージ的に、まぁそうですよねー

ということで、pomだったらzipに食わせなければいいというソリューション。
※findAll で 終端がpom以外なら を入れる

jar {
    manifest {
        attributes 'Main-Class': 'HOGEHOGE'
    }
    from {
        configurations
                .compile
                .findAll { !it.name.endsWith('pom') }
                .collect { it.isDirectory() ? it : zipTree(it) }
    }
}

意外と記事がなかったのでどなたかの参考になれば。

【参考サイト】
https://stackoverflow.com/questions/52816630/unable-to-create-a-jar-of-my-jda-project-because-of-pom-dependency
https://qiita.com/informationsea/items/cd1d8d130a5c7b0bc31a

1
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
1
1