Gradle Webinar – Explore the latest features in Gradle Cloud Services September 2016

updated_logo_for_gradle
The Gradle Scan is data captured during the execution of the build. It allows better understanding of the execution and provides opportunities for improvements including speedup of the execution, diagnosing issues and sharing build data.
The Scan is implemented as Gradle plugin which collects and uploads the build data.

I participated in the September 2016Β webinar and some new useful features were introduced, now I want to share them. But first let’s do a Scan with the initial release (1.0). This will allow to identify the new features easily.

For the Scan execution, a plugin named com.gradle.build-scan must be applied. It is provided by Gradle. To use it, it must be available at the classpath of the buildscript. To do that, following snippet can be used:

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "com.gradle:build-scan-plugin:1.0"
  }
}

The repositories block defines a Mavan layout repository from which can be downloaded the scan plugin. When the repository is available, the actual buildscript dependency for the classpath has to defined. For now I will use the plugin with group: com.gradle, name: build-scan-plugin and version: 1.0 (first release of the scan plugin).
As next step the plugin must be applied in the build script. This provides the logic which performs the scan:

apply plugin: 'com.gradle.build-scan'

The usage of the build scan requires explicit agreement with the terms of service. They are available at Gradle Scan Terms of Service. I recommend to read them before any further actions. To accept the agreement, in the build script must be added:

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

The scan result will be uploaded to the Gradle public cloud and regarding the terms of service, Gradle owns the build scan data. If the public cloud is not for you, you might be interested in Gradle Enterprise

Let’s look a real example, for base I will use the gradle equinox plugin which I developed in my previous articles. In the root build.gradle file, I added the snippets above:

apply plugin: 'groovy'
apply plugin: 'com.gradle.build-scan'

...

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

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "com.gradle:build-scan-plugin:1.0"
    }
}

Now the plugin is applied and the scan can be executed, but a command line option is required to activate it: -Dscan

>gradlew clean test -s -Dscan

The output is:

:clean
:compileJava UP-TO-DATE
:compileGroovy
:processResources
:classes
:createClasspathManifest
:compileTestJava UP-TO-DATE
:compileTestGroovy
:processTestResources UP-TO-DATE
:testClasses
:test

BUILD SUCCESSFUL

Total time: 13.367 secs

WARNING: The build-scan plugin was applied after other plugins.
The captured data is more comprehensive when the build-scan plugin is applied first.

Please see https://gradle.com/help/plugin-late-apply for how to resolve this problem.

Publishing build information…
https://gradle.com/s/2v27xptfohjju

As you can see, a link is printed in the console. When you open it, the following detailed build execution information is available: performance, tests, tasks, projects, dependencies, plugins, switches, infrastructure, console output and another useful information:
webinar-1

Besides the execution details like “what was executed”, “how long it takes”, the environment, etc., can be found suggestions like performance improvement.

Now let’s enable the newest version of the plugin – 1.1
The improvements acoring the documentation:

  • Build Scans can capture user-defined tags, links, and values
  • Build Scans can be automatically published for every build or for every failing build
  • Build Scans can be published retroactively
  • Build Scans are not published when using –offline but still captured for retroactive publication
  • Build Scans can be published over untrusted server connection

Let’s add some tags, links and values to the scan. To do that, the buildScan block must be configured:

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

    link 'GitHub', 'https://github.com/t-mazgalov/gradle-equinox'
    tag 'Local'
    value 'Git Branch', 'git branches'.execute().text
}
buildscript {
    ...
    dependencies {
        classpath "com.gradle:build-scan-plugin:1.1"
    }
}

The generated link after the execution: https://gradle.com/s/btbplojhzxsjc
webinar-2

Next feature, that I want to mention is publication of scan for previous build. For example if I execute build and after that do cleanup with the clean task, the previous build will be wipe outed. The build data for the previous build still can be published, just the buildScanPublishPrevious task should be executed and the build data for the previous build will be uploaded to the cloud.

Gradle also introduced option for publishing every execution without the -Dscan parameter. To activate it, publishAlways() must be added to the buildScan block:

buildScan {
    ...
    publishAlways()
}

During the webinar some future features were mentioned:

  • Pre-defined dependencies filter – the idea behind this is providing mechanism for identifying dependencies resolution issues easily, for example can be shown only the dependency conflicts in the dependency graph
  • Build comparison – this allows to compare builds, for example the build execution is successful locally, but it fails during the CI execution. With this feature, both build can be compared and the differences between them will be identified, e.g. the Java version, the dependencies, the projects, etc. I think that this is pretty nice feature πŸ™‚
  • Trending analytics – analyzes the build like the execution duration over time, the build failures rate, etc.
  • Users and teams – the build scans can be filters by user or by team, e.g. show all my builds or show all team builds

I like the new features and the new future features πŸ™‚ What do you think?
gradlephant-scan

Leave a Reply

Your email address will not be published. Required fields are marked *