AbstractMethodError when moving a class from one module to another in a gradle groovy project

Viewed 18

I'm getting this exception at runtime, I've replaced the actual class name with com.foo.Bar

java.lang.AbstractMethodError: Receiver class com.foo.Bar does not define or inherit an implementation of the resolved method 'abstract void setProperty(java.lang.String, java.lang.Object)' of interface groovy.lang.GroovyObject.

This is a groovy project, and I'm pretty sure there is something wrong with Gradle. As I get this exception when I moved a class from one module to another. There is the only change I made, and it worked before when it was in the other module, but in the class path as implementation project(":foobar").

I have a structure in my project like:

/build.gradle
/app/build.gradle
/util/build.gradle

And I moved the class from util to app. These build.gradle files both have the same groovy version in their classpath with the same groovy plugin.

I am stumped.

Edit After doing some digging I thought I might check what the difference is between the compiler produces and they differ significantly!!

The working version has more annotations:

  @Generated
  public Object call(Object args) {
      return this.doCall(args);
  }

  @Generated
  public Object call() {
      return this.doCall((Object)null);
  }

Also has this stuff at the bottom:

Working


    @Generated
    @Internal
    @Transient
    public MetaClass getMetaClass() {
        MetaClass var10000 = this.metaClass;
        if (var10000 != null) {
            return var10000;
        } else {
            this.metaClass = this.$getStaticMetaClass();
            return this.metaClass;
        }
    }

    @Generated
    @Internal
    public void setMetaClass(MetaClass var1) {
        this.metaClass = var1;
    }
1 Answers

Ok I did figure out what the issue was for anyone else having this problem. To ensure all my modules had the same version of groovy, in /build.gradle I had:

subprojects {
  dependencies {
    constraints {
      implementation "org.codehaus.groovy:groovy:someVersion"
   }
 }
}

But meanwhile I was using io.spring.dependency-management plugin. This plugin specified some other version behavior of groovy, which ended up meaning that app and util had different groovy settings.

The fix was just figuring out what version of groovy was actually being used with the version of the Spring Plugins I was using. I did this by generating a new project with Spring Initializr and running gradle dependencies. And then setting someVersion to this value. In my case this was 3.0.12.

Related