Error compiling groovy enum after upgrading to gradle 2.3.4

We have a groovy application using groovy 2.4.3. We compile and run on JDK 8. I have JDK 1.8.0_31 on my machine. We have some enums written in groovy that have an abstract method that is then implemented for each value in the enum. Once we upgraded from gradle 2.3 to gradle 2.4, we are getting the following compile error:

error: modifier abstract not allowed here
public abstract enum QuestionTypes

Groovy class looks like:

enum QuestionTypes {
GRID_CLICK {
    @Override
    Question getQuestion(Browser browser, int index, WebElement questionRegion, SurveyPage currentPage) {
        return new QuestionGrid(browser, index, questionRegion, currentPage)
    }
},
GENDER_IMAGE {
    @Override
    Question getQuestion(Browser browser, int index, WebElement questionRegion, SurveyPage currentPage) {
        return new GenderImageQuestion(browser, index, currentPage)
    }

abstract Question getQuestion(Browser browser, int index, WebElement questionRegion, SurveyPage currentPage)

}

Paul, I was able to recreate this issue but only when using Groovy joint compilation. That said, I get the same error in Gradle 2.3. What is happening is when joint compilation is enabled (mixed Java/Groovy source), the Groovy generated Java stub for this enum is being marked as abstract which isn’t allowed. I’m going to look into raising an issue with the Groovy folks regarding this.

You have a few options here as I see it:

  1. Don’t use joint compilation. So separate your Java and Groovy sources into src/main/java and src/main/groovy, respectively. If you need to use this enum from Java code this won’t be possible.
  2. Implement the enum in Java rather than Groovy.
  3. Instead of marking the method as abstract provide an implementation that throws an exception. This is probably the worst solution, as you lose compile-time safety.

I’ve gone ahead and opened up an issue against Groovy for this.

https://issues.apache.org/jira/browse/GROOVY-7415

I have not figured out why it’s working for us when using gradle 2.3 .

Thank you for the options.

It is possible that the generated stubs were simply not being compiled in 2.3. This is likely due to the following change in 2.4.

http://gradle.org/docs/current/release-notes#changes-to-groovy-compilation-when-annotation-processors-are-present