Loading...

Monday, November 16, 2009

Gradle Goodness: Display Gradle Information in the Build

In a Gradle build script we can access properties from Gradle and the project itself. To access the Gradle object we use the gradle property. Properties of the Project instance can be accessed directly in our script. We can use this information to display an information message each time we run the build script. Let's make it look like something we also see when we run Grails:

// File: build.gradle
println """\
Welcome to Gradle $gradle.gradleVersion - http://www.gradle.org
Gradle home is set to: $gradle.gradleHomeDir
Gradle user directory is set to: $gradle.gradleUserHomeDir

Base directory: $projectDir
Running script ${relativePath(buildFile)}
"""

If we run the gradle we get to see the information:

$ gradle -t
Welcome to Gradle 0.8 - http://www.gradle.org
Gradle home is set to: D:\java\gradle\gradle-0.8
Gradle user directory is set to: C:\Documents and Settings\mrhaki\.gradle

Base directory is: D:\mrhaki\data\projects\mrhaki.com\blog\posts\samples\info
Running script build.gradle

:reportTask

---------------------------------------------------------
Root Project
---------------------------------------------------------
No tasks

BUILD SUCCESSFUL

Total time: 1.484 secs

0 comments:

Post a Comment