miyohideの日記

技術的なメモなどを記しています

2019年1月22日(火)

なんかバタバタ忙しい

license-gradle-pluginがうまく動いた

1月17日の日記で、license-gradle-pluginがうまく動かないということを書いた。

miyohide.hatenadiary.jp

ようやく解決方法がわかった。

./gradlew dependenciesの出力結果がヒントになった。

$  ./gradlew dependencies

> Task :dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

annotationProcessor - Annotation processors and their dependencies for source set 'main'.
No dependencies

apiElements - API elements for main. (n)
No dependencies

archives - Configuration for archive artifacts.
No dependencies

bootArchives - Configuration for Spring Boot archive artifacts.
No dependencies

compile - Dependencies for source set 'main' (deprecated, use 'implementation' instead).
No dependencies

compileClasspath - Compile classpath for source set 'main'.
\--- org.springframework.boot:spring-boot-starter -> 2.1.2.RELEASE
     +--- org.springframework.boot:spring-boot:2.1.2.RELEASE
     |    +--- org.springframework:spring-core:5.1.4.RELEASE
     |    |    \--- org.springframework:spring-jcl:5.1.4.RELEASE
     |    \--- org.springframework:spring-context:5.1.4.RELEASE
     |         +--- org.springframework:spring-aop:5.1.4.RELEASE
(以下省略)

ここでcompileの部分がNo dependenciesになっているからlicense-gradle-pluginを動かしても空だったんだ。そこで、build.gradleに以下を追加する。

downloadLicenses {
    dependencyConfiguration = 'runtimeClasspath'
}

runtimeClasspathの部分は./gradlew dependenciesの出力結果から良さげなものを選んだ。これで./gradlew downloadLicensesを実行すると、

$ ./gradlew downloadLicenses

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

$ ls -l build/reports/license/
total 80
-rw-r--r--  1 miyohide  staff  8674  1 22 21:50 dependency-license.html
-rw-r--r--  1 miyohide  staff  3828  1 22 21:50 dependency-license.json
-rw-r--r--  1 miyohide  staff  4436  1 22 21:50 dependency-license.xml
-rw-r--r--  1 miyohide  staff  4320  1 22 21:50 license-dependency.html
-rw-r--r--  1 miyohide  staff  1440  1 22 21:50 license-dependency.json
-rw-r--r--  1 miyohide  staff  2002  1 22 21:50 license-dependency.xml

$ more build/reports/license/dependency-license.json
{"dependencies":[{"name":"org.springframework:spring-expression:5.1.4.RELEASE","file":"spring-expression-5.1.4.RELEASE.jar","licenses":[{"name":"Apache License, Version 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}]},{"name":"org.springframework:spring-aop:5.1.4.RELEASE","file":"spring-aop-5.1.4.RELEASE.jar","licenses":[{"name":"Apache License, Version 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}]},{"name":"org.springframework.boot:spring-boot-starter:2
(以下省略)

やったあ。動いたあ。