[Script] Script for adding serialVersionUID to all java files which implements Serializable













According to Serializable java doc: "it is strongly recommended that all serializable classes explicitly declare serialVersionUID values" but sometimes it's easy to forget to add it. With this script you are able to add automatically a serial version uid generated with a random value.

#!/bin/bash  

files=$(find . -name '*.java' | xargs grep -i -l "Serializable"  | xargs grep "interface" -L | xargs grep "serialVersionUID" -L)

for f in  $files
do
 serial=$(jot -r 1 1000000000000 9999999999999)
 echo "Adding serialVersionUID $serial to $f"
        
sed -i '' "/implements Serializable/ a\  
    private static final long serialVersionUID =${serial}L;
" $f

done



* Tested on mac os x 10.8.5

Nessun commento: