使用gradle时无法推断groovy类路径

时间:2018-03-05 22:11:23

标签: gradle groovy

我有一个简单的Gradle项目:

apply plugin: 'groovy'
apply plugin: 'application'

mainClassName = 'HelloWorld'

src/main/groovy中使用一个Groovy源文件:

public class HelloWorld {
    public static void main(String[] args) {
        print "hello world"
    }
}

我输入gradle run并收到以下错误:

FAILURE: Build failed with an exception.

* What went wrong:
Cannot infer Groovy class path because no Groovy Jar was found on class path: [/Users/jzwolak/files/experimenting/gradle/groovy-project/build/classes/java/main]

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED in 0s
1 actionable task: 1 executed

如何为Gradle配置Groovy类路径?

我在/usr/local/opt/groovy/libexec/

处有Groovy

1 个答案:

答案 0 :(得分:8)

您需要声明一个groovy依赖项,如文档https://docs.gradle.org/current/userguide/groovy_plugin.html#sec:groovy_dependency_management

中所示
repositories {
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.14'
}