Search code examples
intellij-ideagroovy

Intellij IDEA reports 'Cannot assign' every time def is used in Groovy


I am struggling to prevent IDEA from complaining about assignment to variable declared by def keyword.

enter image description here

The assignment is absolutely safe as far as I can tell (I observe the same for literals of other types assigned to defed variables). I do not see why assigning Integer into Object would be a problem in the first place.

There does not seem to be any explanation in inspections settings (Groovy > Assignment issues > Incompatible type assignments) nor any fine grained configuration to tune this. When turned off completely, it stops reporting real problems like Integer a = "" as well.

How do I get it to report real problems without highlighting safe assignments?


Solution

  • IntelliJ IDEA can not relay grok the groovy code unless there are both Groovy and Java SDKs configured. By importing the project Groovy got configured automatically, but Java did not.