The Gradle Interface: Gradle Build Metadata

As I’ve shown in previous posts such as “Identifying Gradle Conventions” and “Evolving Gradle Build from Ant Build: Importing Ant Build File“, significant information about a Gradle build can be gleaned by accessing Gradle’s APIs via Groovy. In this post, I look demonstrate accessing basic Gradle build details via the Gradle interface.

The org.gradle.api.invocation.Gradle interface is accessible in the Gradle build file via simply “gradle” [which implicitly corresponds to getGradle() in Groovy parlance]. The next Gradle build script listing shows a subset of the metadata information available via the Gradle interface.
 
 

build-gradle-interface.gradle

// build-gradle-interface.gradle
apply plugin: 'java'

println "Class: ${this.getClass().canonicalName}"
println "Gradle: ${gradle.getClass().canonicalName}"
println "Ant: ${ant.getClass().canonicalName}"
println "Root Project: ${rootProject.getClass().canonicalName}"

println "\n=== Gradle ==="
println "\tgradleVersion = ${gradle.gradleVersion}"
println "\tgradleHomeDir = ${gradle.gradleHomeDir}"
println "\tgradleUserHomeDir = ${gradle.gradleUserHomeDir}"

println "\n=== Gradle.startParameter ==="
def startParameter = gradle.startParameter
println "\tcurrentDir = ${startParameter.currentDir}"
println "\tprojectDir = ${startParameter.projectDir}"
println "\tgradleUserHomeDir = ${startParameter.gradleUserHomeDir}"
println "\tbuildFile = ${startParameter.buildFile}"
println "\tprojectProperties = ${startParameter.projectProperties}"
println "\tsystemPropertiesArgs = ${startParameter.systemPropertiesArgs}"
println "\ttaskNames = ${startParameter.taskNames}"

When I run the Gradle build above and specify that the “jar” task (a task provided by the Java plugin) should be run, the output appears as follows:

gradleInterface

The above build listing and associated screen snapshot indicate that the Gradle interface provides metadata such as version of Gradle, the Gradle installation’s home directory, and the Gradle user’s directory. The Gradle interface also provides access to an instance of StartParameter that provides further build start-up metadata details such as project directory, current directory, the name of the build file, project properties, system properties, and names of tasks that were specified for execution.

There is significantly more information that can be gleaned about a Gradle build from the Gradle interface and this post only shows a subset of that information.
 

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


seven × 7 =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close