IntelliJ IDEA generating serialVersionUID

前端 未结 12 2121
生来不讨喜
生来不讨喜 2020-12-04 05:04

How do generate this value in IntelliJ IDEA?

I go to Settings -> Errors -> Serialization issues -> Serializable class without ‘serialVersi

12条回答
  •  死守一世寂寞
    2020-12-04 05:30

    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:

    $serial$
    

    Now edit variables and set serial to:

    groovyScript("(System.env.JDK_HOME+'/bin/serialver -classpath '+com.intellij.openapi.fileEditor.FileDocumentManager.instance.getFile(_editor.document).path.replaceAll('/java/.*','').replaceAll('/src/','/build/classes/')+' '+_1).execute().text.replaceAll('.*: *','')",qualifiedClassName())
    

    It assumes the standard Gradle project layout. Change /build/ to /target/ for Maven.

提交回复
热议问题