We can have project level extra properties in gradle. These properties are accessible throughout the script.

To set some properties, we can do it as:

project.ext {
  myVar = "A variable"
  isProcessStarted = null
}

Some examples of using these properties are given below.

/** Task which starts some process */
task startProcess() << {
  project.isProcessStarted = true
}
/** Task which stops a process */
task stopProcess() << {
  project.isProcessStarted = false
}
/* Stop the process only if the process was started */
stopProcess.onlyIf {
  project.isProcessStarted == true 
}