catch32
catch32

Reputation: 18582

How to generate serial version UID in Intellij

When I used Eclipse it had a nice feature to generate serial version UID.

But what to do in IntelliJ?

How to choose or generate identical serial version UID in IntelliJ?

And what to do when you modify old class?

If you haven't specify the id, it is generated at runtime...

Upvotes: 251

Views: 285107

Answers (4)

Serhii Maksymchuk
Serhii Maksymchuk

Reputation: 5424

Without any plugins:

You just need to enable highlight: (Idea v.2016, 2017 and 2018, previous versions may have same or similar settings)

File -> Settings -> Editor -> Inspections -> Java -> Serialization issues -> Serializable class without 'serialVersionUID' - set flag and click 'OK'. (For Macs, Settings is under IntelliJ IDEA -> Preferences...)

For Idea v. 2022.1 (Community and Ultimate) it's on:

File -> Settings -> Editor -> Inspections -> JVM Languages -> Serializable class without 'serialVersionUID' - set flag and click 'OK'

Now, if your class implements Serializable, you will see highlight and alt+Enter on class name will ask you to generate private static final long serialVersionUID.

UPD: a faster way to find this setting - you might use hotkey Ctrl+Shift+A (find action), type Serializable class without 'serialVersionUID' - the first is the one.

Upvotes: 515

jeremysprofile
jeremysprofile

Reputation: 11435

Easiest method: Alt+Enter on

private static final long serialVersionUID = ;

IntelliJ will underline the space after the =. put your cursor on it and hit alt+Enter (Option+Enter on Mac). You'll get a popover that says "Randomly Change serialVersionUID Initializer". Just hit enter, and it'll populate that space with a random long.

Upvotes: 283

Meo
Meo

Reputation: 12491

Install GenerateSerialVersionUID plugin

Upvotes: 36

Patch Rhythm
Patch Rhythm

Reputation: 69

IntelliJ IDEA Plugins / GenerateSerialVersionUID https://plugins.jetbrains.com/plugin/?idea&id=185

very nice, very easy to install. you can install that from plugins menu, select install from disk, select the jar file you unpacked in the lib folder. restart, control + ins, and it pops up to generate serial UID from menu. love it. :-)

Upvotes: 3

Related Questions