Skip to content

Instantly share code, notes, and snippets.

@sasuw
Created May 23, 2018 12:54
Show Gist options
  • Select an option

  • Save sasuw/c92787de5ef72aa43183c69bb76fd133 to your computer and use it in GitHub Desktop.

Select an option

Save sasuw/c92787de5ef72aa43183c69bb76fd133 to your computer and use it in GitHub Desktop.
Automatically modify Java files adding serialVersionUID for all classes implementing Serializable, if they do not already contain serialVersionUID
!#!/bin/bash
grep -lir --include \*.java -e 'implements java.io.Serializable' -e 'implements Serializable' . | xargs grep -Lir -e 'serialVersionUID' | while read -r line ; do awk '/implements (java.io.)?Serializable/{print;print "\n\t\nprivate static final long serialVersionUID = 1L;";next}1' $line > temp.java && mv temp.java $line ; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment