License-Gradle-Pluginとは
License-Gradle-Pluginとは、gradleプロジェクトで、dependancesに追加したオープンソースのライブラリのライセンスを、xmlなどで出力してくれるプライグインです。
簡単な使い方などは、以下の記事をご覧ください。
・build.gradleのdependenciesに追加されたライブラリのライセンス情報を出力する
・gradleでdependenciesのライセンス一覧を出力する
jarの追加
今回はプライグインの追加なので、dependancesではなくpluginsに追加していきます。
plugins {
id 'com.github.hierynomus.license' version '0.15.0'
}
実行手法
とりあえず、今回はdependancesで使いしたもののライセンスを纏めるだけなので、
Gradle -> Tasks -> license -> downloadLicense を実行しましょう。
エラー
実行すると、何やら全く関係ない依存関係はあるライブラリの.pomファイルに異常をきたしました。
エラーメッセージはこの通りです。
1:16:53: Executing task 'downloadLicenses'...
> Task :downloadLicenses FAILED
Unable to parse POM file for org.codehaus.plexus:plexus:1.0.4
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':downloadLicenses'.
> org.xml.sax.SAXParseException; systemId: file://C/Users/<ユーザー名>/.gradle/caches/modules-2/files-2.1/org.codehaus.plexus/plexus/1.0.4/<ディレクトリ名>/plexus-1.0.4.pom; lineNumber: 150; columnNumber: 34; エンティティ"oslash"が参照されていますが、宣言されていません。
* 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 3s
1 actionable task: 1 executed
エンティティ"oslash"が参照されていますが、宣言されていません。
1:16:57: Task execution finished 'downloadLicenses'.
エンティティ"oslash"が参照されていますが、宣言されていません。
これがエラーの内容の様です。
調べてみたところ、以下のような質問に辿り着きました。
・Problems with symbol ø
このエラーは、
- org.codehaus.plexusというライブラリのplexus-1.0.4.pomというxml(pom)内でø(oslash)という文字を特殊コードとして利用しようとしている。
- Unicodeで2バイト文字であるøは、直接入力したくないため、特殊文字として入力する。
(現にHTMLではøでエスケープ可能。参考:HTMLの特殊文字) - Gradleがøを特殊文字として認識できない
という流れに沿って生まれたようです。
解決
仕方がないので、plexus-1.0.4.pomを編集することにしました。
エラーメッセージに書いてある通り、
C/Users/<ユーザー名>/.gradle/caches/modules-2/files-2.1/org.codehaus.plexus/plexus/1.0.4/<ディレクトリ名>/plexus-1.0.4.pom
というファイルの150行目、34文字目にøはあるようです。
回答には、
I have found that if i replace ø with Ø in my request then all works fine.
(øをØと交換して使用した場合、その後すべてがうまくいきます。)
とありましたので、このøをØに書き換えればいいようです。
一応、変更箇所付近を抜粋しておきます。
<developer>
<name>Trygve Laugstøl</name>
<id>trygvis</id>
<email>trygvis@codehaus.org</email>
<roles>
<role>Developer</role>
</roles>
</developer>
<developer>
<name>Trygve LaugstØl</name>
<id>trygvis</id>
<email>trygvis@codehaus.org</email>
<roles>
<role>Developer</role>
</roles>
</developer>
これでエラーが消え、普通に実行できるはずです。
特に設定を行っていない場合、生成されたファイルは、
build -> reports -> license
内に生成されます。
うちの環境では、以下の6ファイルが生成されました。
dependency-license.html
dependency-license.json
dependency-license.xml
license-dependency.html
license-dependency.json
license-dependency.xml