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

问题描述 投票:7回答:1

我有一个简单的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

gradle groovy
1个回答
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'
}
© www.soinside.com 2019 - 2024. All rights reserved.