How do generate this value in IntelliJ IDEA?
I go to Settings -> Errors -> Serialization issues -> Serializable class without ‘serialVersionUID’, but it still doesn't show me the warning. My class PKladrBuilding parent implements interface Serializable.
Part of the code:
public class PKladrBuilding extends PRQObject
public abstract class PRQObject extends PObject
public abstract class PObject implements Serializable
Without any plugins: You just need to enable highlight in IntelliJ:
IntelliJ Preferences -> Editor -> Inspections -> Java -> Serialization issues -> Serializable class without 'serialVersionUID'
- set flag and click'OK'
.Now, if your class implements
Serializable
, you will see highlight, andalt+Enter
on class name will propose to generateprivate static final long serialVersionUID
.With version
v2018.2.1
Go to
A warning should appear next to the class declaration.
Install the GenerateSerialVersionUID plugin by Olivier Descout.
Go to: menu File → Settings → Plugins → Browse repositories →
GenerateSerialVersionUID
Install the plugin and restart.
Now you can generate the id from menu Code → Generate → serialVersionUID` or the shortcut.
Add a live template called "ser" to the other group, set it to "Applicable in Java: declaration", and untick "Shorten FQ names". Give it a template text of just:
Now edit variables and set serial to:
It assumes the standard Gradle project layout. Change /build/ to /target/ for Maven.
In addition you can add live template that will do the work.
To do it press Ctrl+Alt+S ->
"Live Templates"
section ->other
(or w/e you wish)And then create a new one with a definition like this:
Then select
definition
scope and save it as'serial'
Now you can type
serial
TAB in class body.In order to generate the value use
and provide the randomLong template variable with the following value: groovyScript("new Random().nextLong().abs()")
https://pharsfalvi.wordpress.com/2015/03/18/adding-serialversionuid-in-idea/