views:

340

answers:

2

Is there a maven plugin which automatically calculates and updates serial version uid for all java class files implementing the Serializable interface?

+2  A: 

I don't know of any Maven plugin that can add this functionality, but you could call the Serialver Ant task using the Maven AntRun Plugin in the process-sources phase of the lifecycle.

Jason Gritman
Did you mean `process-sources`?
Pascal Thivent
Yes that is what I meant. Editing now. Thanks!
Jason Gritman
I will probably go with antrun for the time being. thanks very much
Joshua
+2  A: 

The compile mojo of the AspectJ compiler Maven Plugin has a XaddSerialVersionUI parameter that:

Causes the compiler to calculate and add the SerialVersionUID field to any type implementing Serializable that is affected by an aspect. The field is calculated based on the class before weaving has taken place.

So you could apply a fake or empty aspect and use this plugin to weave your classes (it's not ideal but I don't think that modifying Java sources directly is really a good practice neither).

Pascal Thivent