Gradle - Changing "compile" to "implementation" get error

Viewed 894

build.gradle - partly:

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

If change compile to implementation, on build will get following error:

Execution failed for task ':greeter:compileJava

Changing it back then build will succeed.

Tips:

  • The project is using Gradle 4.10, which do support implementation.
  • There are other dependencies, in the sub projects, change to use implementation won't cause issue, only this single line will.

Any help?

1 Answers

I was wondering why your main java project would need groovy-all as it's used to compile the groovy library. implementation configuration should be enough.

I did reproduce your issue and focus on the error thanks to your link :

: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

Why is GroovyObject needed to compile your java code ? I looked into GroovyObject source code and it hit me :

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 {
[...]

The interface implemented by all Groovy objects. Especially handy for using Groovy objects when in the Java world.

GreetingFormatter is a Groovy object and implicitly implements GroovyObject. That's why groovy-all is needed in the compile classpath i.e. it should be declare as a compile dependency in the groovy library.

Related