build.gradle-部分:
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.15'
}
如果将compile
更改为implementation
,则在构建时将出现以下错误:
任务':greeter:compileJava的执行失败
将其还原然后构建将成功。
提示:
Gradle 4.10
,它确实支持implementation
。implementation
不会引起问题,只有这一行会导致问题。有帮助吗?
答案 0 :(得分:1)
我想知道为什么您的主要Java项目需要groovy-all
来编译groovy库。 implementation
配置应该足够。
由于您的链接,我确实重现了您的问题并专注于错误:
:greeter:compileJava FAILED
/mnt/star/git_repository/workspace/groovy_workplace/gradle/hello/hello_multi_project/greeter/src/main/java/greeter/Greeter.java:5: error: cannot access GroovyObject
final String output = GreetingFormatter.greeting(args[0]);
^
class file for groovy.lang.GroovyObject not found
为什么需要GroovyObject
来编译Java代码?我查看了GroovyObject
源代码,结果让我大吃一惊:
package groovy.lang;
/**
* The interface implemented by all Groovy objects.
* <p>
* Especially handy for using Groovy objects when in the Java world.
*
* @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
*/
public interface GroovyObject {
[...]
所有Groovy对象实现的接口。特别方便 在Java世界中使用Groovy对象。
GreetingFormatter
是一个Groovy对象,它隐式实现GroovyObject
。这就是为什么在编译类路径中需要groovy-all
的原因,即应该在groovy库中将其声明为compile
依赖项。