Gaining insight into a Gradle build

Every Gradle build has access to a default set of tasks that can deliver insight information on your build settings. You probably have come across the dependencies task. This task can display dependencies associated with all configurations of a particular project; you can even instruct which configuration to be queried if the list of configurations happens to be very long. Let's say we have a Java project that looks like this

build.gradle

plugins {
    id 'java'
    id 'org.kordamp.gradle.project' version '0.11.0'
}

ext.build_property = 'build'

config {
    license    { enabled = false }

    publishing { enabled = false }
}

repositories {
    jcenter()
    mavenCentral()
    flatDir { dirs 'lib' }
}

dependencies {
    testCompile 'junit:junit:4.12'
}

Invoking the dependencies task for this project yields

$ gradlew dependencies --configuration=testCompile

> Task :dependencies

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

testCompile - Dependencies for source set 'test' (deprecated, use 'testImplementation' instead).
\--- junit:junit:4.12
     \--- org.hamcrest:hamcrest-core:1.3

A web-based, searchable dependency report is available by adding the --scan option.

BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed

There's another task named properties which displays all the properties that a Gradle project instance has. Unfortunately this task also displays the list of all plugin instances, configurations, extensions, tasks, and other semi-private (implementation details) that may not be relevant to some degree. However if you apply the org.kordamp.gradle.base plugin to your project you gain access to 4 new tasks that display this information segregated by responsibility. This tasks are:

  • projectProperties
  • extensions
  • repositories
  • plugins

To demonstrate this I'll add global, local, and project properties to the build in the following way

~/.gradle/gradle.properties

global_property = global

gradle.properties

version        = 0.0.0
group          = org.kordamp.sample.acme
local_property = local

Then invoke the build with the following command

$ gradlew projectProperties -Pproject_property=project

> Task :projectProperties
project:
    name: sample
    version: 0.0.0
    group: org.kordamp.sample.acme
    path: :
    displayName: root project 'sample'
    projectDir: /tmp/sample
    buildFile: /tmp/sample/build.gradle
    buildDir: /tmp/sample/build

ext:
    build_property: build
    global_property: global
    local_property: local
    project_property: project

Notice that properties that inherently belong to the Project instance are put into a separate section from those that are added dynamically (the ext block). You can also obtain a list of all extensions currently applied to the project

$ gradlew extensions

> Task :extensions
extension 0:
    name: ext
    type: org.gradle.api.plugins.ExtraPropertiesExtension

extension 1:
    name: defaultArtifacts
    type: org.gradle.api.internal.plugins.DefaultArtifactPublicationSet

extension 2:
    name: config
    type: org.kordamp.gradle.plugin.base.ProjectConfigurationExtension

extension 3:
    name: reporting
    type: org.gradle.api.reporting.ReportingExtension

extension 4:
    name: jacoco
    type: org.gradle.testing.jacoco.plugins.JacocoPluginExtension

extension 5:
    name: downloadLicenses
    type: nl.javadude.gradle.plugins.license.DownloadLicensesExtension

extension 6:
    name: license
    type: nl.javadude.gradle.plugins.license.LicenseExtension

extension 7:
    name: signing
    type: org.gradle.plugins.signing.SigningExtension

extension 8:
    name: effectiveConfig
    type: org.kordamp.gradle.plugin.base.ProjectConfigurationExtension

extension 9:
    name: versioning
    type: net.nemerosa.versioning.VersioningExtension

extension 10:
    name: bintray
    type: com.jfrog.bintray.gradle.BintrayExtension

This task prints out the type and name of each extension. You may also list all repositories used to resolve dependencies, for example

$ gradlew repositories

> Task :repositories
repository 0:
    type: maven
    name: BintrayJCenter
    url: https://jcenter.bintray.com/

repository 1:
    type: maven
    name: MavenRepo
    url: https://repo.maven.apache.org/maven2/

repository 2:
    type: flatDir
    name: flatDir
    dirs:
        /tmp/sample/lib

Finally, you can also list all plugins that have been applied to a project

$ gradlew plugins

> Task :plugins
plugin 0:
    implementationClass: org.gradle.api.plugins.HelpTasksPlugin

plugin 1:
    implementationClass: org.gradle.language.base.plugins.LifecycleBasePlugin

plugin 2:
    implementationClass: org.gradle.api.plugins.BasePlugin

plugin 3:
    id: org.kordamp.gradle.base
    implementationClass: org.kordamp.gradle.plugin.base.BasePlugin
    enabled: true

plugin 4:
    implementationClass: org.gradle.api.plugins.ReportingBasePlugin

plugin 5:
    implementationClass: org.gradle.testing.jacoco.plugins.JacocoPlugin

plugin 6:
    id: org.kordamp.gradle.jacoco
    implementationClass: org.kordamp.gradle.plugin.jacoco.JacocoPlugin
    enabled: true

plugin 7:
    id: com.github.hierynomus.license-report
    implementationClass: com.hierynomus.gradle.license.LicenseReportingPlugin

plugin 8:
    id: com.github.hierynomus.license-base
    implementationClass: com.hierynomus.gradle.license.LicenseBasePlugin

plugin 9:
    id: license
    implementationClass: nl.javadude.gradle.plugins.license.LicensePlugin

plugin 10:
    id: org.kordamp.gradle.license
    implementationClass: org.kordamp.gradle.plugin.license.LicensePlugin
    enabled: false

plugin 11:
    id: org.kordamp.gradle.build-info
    implementationClass: org.kordamp.gradle.plugin.buildinfo.BuildInfoPlugin
    enabled: true

plugin 12:
    id: org.kordamp.gradle.source-jar
    implementationClass: org.kordamp.gradle.plugin.source.SourceJarPlugin
    enabled: true

plugin 13:
    id: org.kordamp.gradle.apidoc
    implementationClass: org.kordamp.gradle.plugin.apidoc.ApidocPlugin
    enabled: true

plugin 14:
    id: org.kordamp.gradle.minpom
    implementationClass: org.kordamp.gradle.plugin.minpom.MinPomPlugin
    enabled: true

plugin 15:
    id: org.kordamp.gradle.jar
    implementationClass: org.kordamp.gradle.plugin.jar.JarPlugin
    enabled: true

plugin 16:
    id: org.kordamp.gradle.publishing
    implementationClass: org.kordamp.gradle.plugin.publishing.PublishingPlugin
    enabled: false

plugin 17:
    implementationClass: org.gradle.plugins.signing.SigningPlugin

plugin 18:
    id: org.kordamp.gradle.source-stats
    implementationClass: org.kordamp.gradle.plugin.stats.SourceStatsPlugin
    enabled: true

plugin 19:
    id: org.kordamp.gradle.source-html
    implementationClass: org.kordamp.gradle.plugin.sourcehtml.SourceHtmlPlugin
    enabled: true

plugin 20:
    id: org.kordamp.gradle.bintray
    implementationClass: org.kordamp.gradle.plugin.bintray.BintrayPlugin
    enabled: false

plugin 21:
    id: com.github.ben-manes.versions
    implementationClass: com.github.benmanes.gradle.versions.VersionsPlugin

plugin 22:
    id: org.kordamp.gradle.project
    implementationClass: org.kordamp.gradle.plugin.project.ProjectPlugin

plugin 23:
    id: net.nemerosa.versioning
    implementationClass: net.nemerosa.versioning.VersioningPlugin

plugin 24:
    id: com.jfrog.bintray
    implementationClass: com.jfrog.bintray.gradle.BintrayPlugin

Take note that some plugins display their enabled status. These plugins belong to the kordamp-gradle-plugins suite and can be enabled/disabled using the Project DSL. Finally, there's the effectiveSettings task that displays all configuration made through the Project DSL. By default it prints all settings but you can limit it by section, for example

$ gradlew effectiveSettings --sections=info,publishing,bintray

> Task :effectiveSettings
info:
    name: sample
    inceptionYear: 2018
    copyrightYear: 2018
    organization:
    links:
    scm:
    specification:
        enabled: true
        title: sample
        version: unspecified
    implementation:
        enabled: true
        title: sample
        version: unspecified
publishing:
    enabled: false
bintray:
    enabled: false

The information provided by these tasks depends on static configuration available in the build. If you'd like to know more about the build when it's actually executed (such as which tasks, how much time they took executing, errors, and other potential hot spots) then have a look at the Gradle Build Scans feature.

Keep on Coding!

Liked it? Take a second to support aalmiray on Patreon!
Become a patron at Patreon!

Trackbacks/Pingbacks

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

ˆ Back To Top