You can create src/main/groovy, put your script called 'myscript.groovy' in there:
println "hello world from groovy version ${GroovySystem.version}"
Then, have a build.gradle file in your project root directory:
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.0.5'
}
task runScript (dependsOn: 'classes', type: JavaExec) {
main = 'myscript'
classpath = sourceSets.main.runtimeClasspath
}
Then, you can execute your script (with output)
hw@hbook:ex $ gradle runScript
:compileJava UP-TO-DATE
:compileGroovy
:processResources UP-TO-DATE
:classes
:runScript
hello world from groovy version 2.0.5
BUILD SUCCESSFUL
Total time: 6.118 secs
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…