Gradle:build scanの使い方、その1

2019年5月21日

build scanというのは、build.gradleファイルの内容を解析した結果を、Gradleチーム(?)の提供するサーバに送り込み、そのウェブサイトで様々な分析ができるというものだ。

当然、build.gradleの内容が送られてしまい、基本的には公開されてしまうので注意が必要。一応「ランダムなURL」が生成され、「消すことも可能」となっている。

セットアップ

Get started with build scansに説明がある。

Gradle4.3以上の場合には、単純にbuild.gradleを用意し、「gradle build –scan」を実行する。

※ハイフンは二つ必要「--scan」
※それ以前のgradleの場合は、別途プラグインの導入が必要らしい。

すると、以下のような表示がされる。

18/12/07 10:20 Executing gradle commands:build --scan  in C:\foobar\sample
Root project 'sample' executing build --scan 
Download https://plugins.gradle.org/m2/com/gradle/build-scan-plugin/1.10.3/build-scan-plugin-1.10.3.pom
Download https://plugins.gradle.org/m2/com/gradle/build-scan-plugin/1.10.3/build-scan-plugin-1.10.3.jar
.....

BUILD SUCCESSFUL in 7s
1 actionable task: 1 executed


The build scan was not published due to a configuration problem.

The Gradle Cloud Services license agreement has not been agreed to.

To agree to the license, include the following in your root project's configuration:
buildScan { licenseAgreementUrl = 'https://gradle.com/terms-of-service'; licenseAgree = 'yes' }

For more information, please see https://gradle.com/scans/help/plugin-license.

Alternatively, if you are using Gradle Enterprise, specify the server location.
For more information, please see https://gradle.com/scans/help/plugin-enterprise-config.

ライセンスに同意しろよと言っているので、build.gradleに次を追加する。

buildScan { 
  licenseAgreementUrl = 'https://gradle.com/terms-of-service'
  licenseAgree = 'yes' 
}

※実際には以下にしている。–scanスイッチをつけない場合にはbuildScanプロパティが現れないので、エラーになってしまうからだ。

if (hasProperty("buildScan")) {
  buildScan { 
    licenseAgreementUrl = 'https://gradle.com/terms-of-service'
    licenseAgree = 'yes' 
  }
}

再度実行してみる。

18/12/07 10:28 Executing gradle commands:build --scan  in C:\foobar\sample
Root project 'sample' executing build --scan 
....

BUILD SUCCESSFUL in 2s
1 actionable task: 1 up-to-date

Publishing build scan...
https://gradle.com/s/bmrgbrzwhydbs

ということで、https://gradle.com/s/bmrgbrzwhydbsに作成されたとある。もちろんここには大したものは入っていない。

アクセスする

このURLにアクセスすると、メールを入力しろという画面になる。

メアドを入力すると、以下のようなメールが来る。

クリックすると、ウェブにアクセスできる。

不思議なことに、パスワード設定もしていないのに、引き続き別のプロジェクトについて「gradle build –scan」を行い、そのURLにアクセスすると、今度はメアド入力は必要無い。

調査の方法は?

こうして分析ウェブにアクセスすることができたが、本当に問題解決の助けになるのだろうか?

今後は使い方を試してみたいと思う。