Skip to content

My attempt to understand the Groovy part of the DSL used by Gradle

Notifications You must be signed in to change notification settings

RaffaeleSgarro/gradle-like-dsl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Explain Gradle DSL for building tasks

Consider the following build.gradle:

task helloWorld {
  println "Hello World"
}

which prints "Hello World" when you invoke gradle helloWorld. I'd like to understand what happens on the Groovy side when it evaluates this script.

According to Gradle documentation, writing task name creates a Task object named name and makes it available as a property of the current delegate object, which is a Project instance.

I can't understand what name is from the Groovy perspective. It's not a string, and I think it's a method call:

helloWorld ( { println "Hello World!" } )

The current Project delegate may use methodMissing to add a task with the given name, but how can it differentiate between these two:

// Ok, task definition
task foo { println "Foo" }

// Should throw MissingMethod, because we don't use task()
bar { println "Bar" }

In fact, my current implementation lacks with respect to this sort of error detection. I'd like to build tasks with the Gradle syntax task foo, but want an exception to be thrown when one doesn't use the task() method to define a task.

See the source on GitHub

About

My attempt to understand the Groovy part of the DSL used by Gradle

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages