I'm playing around with the samples directory that comes with Gradle and trying to create a simple task that runs a groovy script which depends on another script.
The structure of the project looks like this:
.
├── build.gradle
└── src
├── main
│ ├── groovy
│ │ └── org
│ │ └── gradle
│ │ └── Person.groovy
│ └── resources
│ ├── resource.txt
│ └── script.groovy
└── test
├── groovy
│ └── org
│ └── gradle
│ └── PersonTest.groovy
└── resources
├── testResource.txt
└── testScript.groovy
I've added the following task in build.gradle
task runScript << {
new GroovyShell().run(file('src/main/resources/script.groovy'))
}
The error I'm getting is:
FAILURE: Build failed with an exception.
* Where:
Build file '/gradle/gradle-1.0/samples/groovy/quickstart/build.gradle' line: 13
* What went wrong:
Execution failed for task ':runScript'.
Cause: No such property: person for class: script
contents of script.groovy
are:
person.name = person.name[0].toUpperCase() + person.name[1..-1]
contents of Person.groovy
are:
package org.gradle
class Person {
String name
def Person() {
getClass().getResourceAsStream('/resource.txt').withStream {InputStream str ->
name = str.text.trim()
}
getClass().getResourceAsStream('/script.groovy').withStream {InputStream str ->
def shell = new GroovyShell()
shell.person = this
shell.evaluate(str.text)
}
}
}
Question
How can I add a task that would simply run script.groovy
which makes use of another groovy class (Person
)