LoginSignup
2
2

More than 5 years have passed since last update.

License-Gradle-Pluginを使った

Last updated at Posted at 2018-12-29

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 ø

このエラーは、
1. org.codehaus.plexusというライブラリのplexus-1.0.4.pomというxml(pom)内でø(oslash)という文字を特殊コードとして利用しようとしている。
2. Unicodeで2バイト文字であるøは、直接入力したくないため、特殊文字として入力する。
(現にHTMLでは&oslash;でエスケープ可能。参考:HTMLの特殊文字)
3. Gradleが&oslash;を特殊文字として認識できない
という流れに沿って生まれたようです。

解決

仕方がないので、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文字目に&oslash;はあるようです。

回答には、
I have found that if i replace &oslash; with &#xD8; in my request then all works fine.
(&oslash;をØと交換して使用した場合、その後すべてがうまくいきます。)
とありましたので、この&oslash;を&#xD8;に書き換えればいいようです。

一応、変更箇所付近を抜粋しておきます。

変更前
    <developer>
      <name>Trygve Laugst&oslash;l</name>
      <id>trygvis</id>
      <email>trygvis@codehaus.org</email>
      <roles>
        <role>Developer</role>
      </roles>
    </developer>
変更後
    <developer>
      <name>Trygve Laugst&#xD8;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
2
2
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
2
2