バタバタしていたらいつの間にか一週間以上更新できていなかった。
license-gradle-pluginがうまく動かない
Javaアプリで「アプリが使っているライブラリの一覧とそのライセンスを知りたい」ってニーズがあったので、何か無いかなと思い調べてたどり着いたのが、hierynomus/license-gradle-plugin。
早速、build.gradle
にプラグインを読み込ませる。
buildscript { ext { springBootVersion = '2.1.2.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } // 以下3行を追加 plugins { id "com.github.hierynomus.license" version "0.15.0" } apply plugin: 'java' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '1.8' repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter' testImplementation 'org.springframework.boot:spring-boot-starter-test' }
あとは、./gradlew downloadLicenses
と打って実行。
$ ./gradlew downloadLicenses Welcome to Gradle 4.10.2! Here are the highlights of this release: - Incremental Java compilation by default - Periodic Gradle caches cleanup - Gradle Kotlin DSL 1.0-RC6 - Nested included builds - SNAPSHOT plugin versions in the `plugins {}` block For more details see https://docs.gradle.org/4.10.2/release-notes.html Starting a Gradle Daemon (subsequent builds will be faster) BUILD SUCCESSFUL in 18s 1 actionable task: 1 executed $
結果は、build/reports/license
以下に出力されるみたい。
$ ls -l build/reports/license/ total 48 -rw-r--r-- 1 miyohide staff 1218 1 17 22:01 dependency-license.html -rw-r--r-- 1 miyohide staff 19 1 17 22:01 dependency-license.json -rw-r--r-- 1 miyohide staff 16 1 17 22:01 dependency-license.xml -rw-r--r-- 1 miyohide staff 1198 1 17 22:01 license-dependency.html -rw-r--r-- 1 miyohide staff 15 1 17 22:01 license-dependency.json -rw-r--r-- 1 miyohide staff 12 1 17 22:01 license-dependency.xml $
あれ?やたらとファイルサイズが小さい。ちょっと中身を見てみよう。
$ head build/reports/license/dependency-license.xml <dependencies /> $
う〜ん、空だ。なんでだろう。
ちなみにbuild.gradle
でimplementation 'org.springframework.boot:spring-boot-starter'
の部分をcompile 'org.springframework.boot:spring-boot-starter'
とし、./gradlew clean && ./gradlew downloadLicenses
を実行すると...
$ cat build/reports/license/dependency-license.xml <dependencies> <dependency name='org.springframework:spring-expression:5.1.4.RELEASE'> <file>spring-expression-5.1.4.RELEASE.jar</file> <license name='Apache License, Version 2.0' url='http://www.apache.org/licenses/LICENSE-2.0' /> </dependency> (以下略)
う〜ん、きちんと出力される。