0

Upgrading a legacy system of grails. One of the controllers implements Serializable. This is throwing the following error in newer versions of grails:

Invalid duplicate class definition of class com.regional.ScheduleController : 
The source contains at least two definitions of the class. 
One of the classes is an explicit generated class using the class statement, 
the other is a class generated from the script body based on the file name. 
Solutions are to change the file name or to change the class name.

The solution mentioned would break (previous) grails convention. Anyone know how to handle this in grails 2.5+?

EDIT

Serializable is not the issue. I tried removing it and got the same error. I found this explanation from another question:

IN groovy.. class B{} is a class structure and defines a class B. 
Scripts are classes too.
 Now you may create a B.groovy, with the content "class B{}; def b = new B()". 
There would be one class named B, and a script with the very same name.
This is a conflict.  

However this does not explain why it runs fine below grails 2.5 and not above it. And I can't find a def conflict like the one mentioned above in that controller.

ANSWER: One of the imports was what was actually failing- in a way that caused groovy to generate a class definition based on the current file name. When it hit the class definition, there was already an auto generated class name to collide with.

Community
  • 1
  • 1
user2782001
  • 3,380
  • 3
  • 22
  • 41

0 Answers0