Larry Cai Larry Cai - 3 years ago 151
Groovy Question

gradle build failure for groovy project on dependence

New to groovy, and I had one groovy project@commit 2f54b59 like below


├── build.gradle
└── src
└── main
└── groovy
├── check.groovy
└── helpers
└── Person.groovy


And the
check.groovy
is simple:

import helpers.*
println "hello"
person = new Person()


I try to use
build.gradle
to manage the project with
sourceSets



sourceSets {
main {
groovy {
srcDirs('.')
include '*.groovy'
}
}
}


and meet error when build:

$ gradle build
:compileJava UP-TO-DATE
:compileGroovy
startup failed:
gradle-sample/src/main/check.groovy: 5: unable to resolve class Person
@ line 5, column 10.
person = new Person()
^

1 error
:compileGroovy FAILED

FAILURE: Build failed with an exception.


If u run the
groovy
command directly, it works fine

$ cd src/main/groovy
$ groovy check.groovy
hello


How to setup the configuration to make it work?

Answer Source

There's no need to configure any source sets - gradle will handle it itself.

See a little demo here.

apply plugin: 'groovy'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download