#development #gradle #java #kotlin

When you do continuous integration using gradle, you often want to keep a proper report with the results of your build. One of the ways to do this is by using build scans.

This is done by adding the --scan parameter to the build task:

 1$ ./gradlew build --scan
 2
 3> Task :test FAILED
 4
 5ParserTests > testParser() FAILED
 6    org.opentest4j.AssertionFailedError at ParserTests.kt:19
 7
 81 test completed, 1 failed
 9
10FAILURE: Build failed with an exception.
11
12* What went wrong:
13Execution failed for task ':test'.
14> There were failing tests. See the report at: file:///Users/me//kotlin-gpx/build/reports/tests/test/index.html
15
16* Try:
17Run 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.
18
19* Get more help at https://help.gradle.org
20
21BUILD FAILED in 3s
2213 actionable tasks: 1 executed, 12 up-to-date
23
24Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https://gradle.com/terms-of-service. Do you accept these terms? [yes, no] yes
25
26Gradle Terms of Service accepted.
27
28Publishing build scan...
29https://gradle.com/s/xdxf4na3bzi6g

In this example, the build failed (on purpose).

If you look carefully or tried this running yourself, you'll notice that there is one thing preventing this from running automatically. Every time you run the command, you have to manually type yes to accept the terms of service. This is something we don't want.

Luckily, there is a way to avoid this from happening by adding the following to the bottom of your build.gradle.kts build script (we're using Kotlin in this case):

1extensions.findByName("buildScan")?.withGroovyBuilder {
2    setProperty("termsOfServiceUrl", "https://gradle.com/terms-of-service")
3    setProperty("termsOfServiceAgree", "yes")
4}

After you've added this, running the build with scan again results in:

 1./gradlew build --scan
 2
 3> Task :test FAILED
 4
 5ParserTests > testParser() FAILED
 6    org.opentest4j.AssertionFailedError at ParserTests.kt:19
 7
 81 test completed, 1 failed
 9
10FAILURE: Build failed with an exception.
11
12* What went wrong:
13Execution failed for task ':test'.
14> There were failing tests. See the report at: file:///Users/me/kotlin-gpx/build/reports/tests/test/index.html
15
16* Try:
17Run 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.
18
19* Get more help at https://help.gradle.org
20
21BUILD FAILED in 2s
2213 actionable tasks: 1 executed, 12 up-to-date
23
24Publishing build scan...
25https://gradle.com/s/wbsdyvsjh5a4q

Way better if you ask me :-)