DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Exploring the Capabilities of eBPF
  • Front-End: Cache Strategies You Should Know
  • What Is JHipster?
  • Using Render Log Streams to Log to Papertrail

Trending

  • Exploring the Capabilities of eBPF
  • Front-End: Cache Strategies You Should Know
  • What Is JHipster?
  • Using Render Log Streams to Log to Papertrail

Gradle Command-Line Conveniences

Dustin Marx user avatar by
Dustin Marx
·
Dec. 29, 13 · Interview
Like (0)
Save
Tweet
Share
11.72K Views

Join the DZone community and get the full member experience.

Join For Free

In my post A First Look at Building Java with Gradle, I briefly mentioned using Gradle's "gradle tasks" command to see the available tasks for a particular Gradle build. In this post, I expand on that brief mention a bit more and look at some related Gradle command-line conveniences.

Gradle makes it easy to determine available Gradle tasks for a given project. The next screen snapshot demonstrates using gradle tasks (or gradle :tasks) in the same directory as the simple Gradle build file (build.gradle) I used in my previously mentioned Gradle post. The screen snapshots follow the code listing of build.gradle which is reproduced here for convenience.

Basic Java Application build.gradle

apply plugin: 'java'  

Adding --all to gradle tasks (gradle tasks --all) will show even more details (including tasks' dependencies) as shown in the next screen snapshot.

Something I used to do often when working with an Ant build file new to me was to add a target "showProperties" that used a series of Ant echo tasks to display the properties used by that build file. Gradle provides essentially this capability out-of-the-box. The next screen snapshot demonstrates use of gradle -q properties to display the properties associated with the Gradle project and tasks in the build.gradle file in the same directory.

Another useful command-line Gradle option is --profile. This can be used in conjunction with running a Gradle command. For example, gradle tasks --profile generates the same standard output as shown above, but also writes build performance statistics to a file with the naming convention profile-YYYY-MM-DD-HH-mm-ss.html in the build/reports/profile subdirectory of the directory from which the build was executed. An example of that generated file is shown next.

The final Gradle command-line option I cover in this post is the "dry run" option -m (or --dry-run). This option allows one to see the Gradle tasks which are run and the order in which they are run without actually executing those tasks. Because the one-line Gradle build.gradle file used in this post applies the Java plugin, the automatically added Gradle Tasks include compileJava, classes, jar, and javadoc. The following screen snapshot demonstrates running gradle -m jar to see the dry run output that shows the dependent tasks that must be run before "jar" and the order they must be run (compileJava->processResources->classes->jar). Note "SKIPPED" notation indicating that the Gradle tasks are not actually executed.

Chapter 11 ("Using the Gradle Command-Line") of the Gradle User Guide (PDF) contains additional details regarding use of Gradle's command-line interface with sections on listing projects, listing tasks, listing project dependencies, listing project properties, and listing the order Gradle tasks are executed.

Gradle Task (computing)

Published at DZone with permission of Dustin Marx, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Exploring the Capabilities of eBPF
  • Front-End: Cache Strategies You Should Know
  • What Is JHipster?
  • Using Render Log Streams to Log to Papertrail

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: