Question

I'm trying to run the simple @Builder example shown on the Groovy 2.3 release page, using IntelliJ Idea 13.1.1.

Having created a vanilla groovy project and pasted the code, I get the following warnings where @Builder is declared on the Person class:

Missed attributes: forClass, prefix, builderClassName, buildMethodName, builderMethodName

(Essentially all the properties which don't have default values.)

The IDE is then also not seeing the builder() method which by default should have been added to the Person class, suggesting the AST hadn't been applied.

When the script is actually executed, it behaves as expected. So why do I see those errors in the IDE?

Update:

If I try to build from Gradle I get the following error during groovy compilation:

Can't load builderStrategy 'groovy.transform.builder.DefaultStrategy' java.lang.ClassCastException: groovy.transform.builder.DefaultStrategy cannot be cast to org.codehaus.groovy.transform.BuilderASTTransformation$BuilderStrategy @ line 3, column 1. @Builder

If I try to switch to SimpleStrategy instead of the DefaultStrategy I get:

The builderStrategy class 'groovy.transform.builder.SimpleStrategy' on @Builder is not a builderStrategy @ line 4, column 1. @Builder(builderStrategy = SimpleStrategy)

Was it helpful?

Solution

IntelliJ doesn't build/consider the Groovy AST. (This would be brittle and slow.) So until someone adds support for @Builder to IntelliJ, it won't understand it. I recommend to file a feature request.

The problem with @Builder and Gradle has been identified as a bug in the @Builder implementation. See my answer on the Gradle Forums.

Update: The Groovy bug filing was resolved with Groovy version 2.3.2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top