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:

$ ./gradlew build --scan

> Task :test FAILED

ParserTests > testParser() FAILED
    org.opentest4j.AssertionFailedError at ParserTests.kt:19

1 test completed, 1 failed

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///Users/me//kotlin-gpx/build/reports/tests/test/index.html

* 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
13 actionable tasks: 1 executed, 12 up-to-date

Publishing 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

Gradle Terms of Service accepted.

Publishing build scan...
https://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):

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

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

./gradlew build --scan

> Task :test FAILED

ParserTests > testParser() FAILED
    org.opentest4j.AssertionFailedError at ParserTests.kt:19

1 test completed, 1 failed

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///Users/me/kotlin-gpx/build/reports/tests/test/index.html

* 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 2s
13 actionable tasks: 1 executed, 12 up-to-date

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

Way better if you ask me :-)

Related Posts

  • Upgrading your Gradle project to version 7
  • Creating a fat jar from gradle
  • Creating a runnable jar using Gradle
  • Using Kotlin and Jsoup to scrape HTML
  • Checking if an Android app is installed via Google Play