Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin all-open compiler plugin doesn't work

Tags:

kotlin

I use Realm and it requires open keyword to it's model classes.

Following https://blog.jetbrains.com/kotlin/2016/12/kotlin-1-0-6-is-here/, I tried to use all-open compiler plugin to remove the open keyword from Realm model classes.

First, I added all-open compiler plugin and set the package name of annotation

buildscript {
  dependencies {
    classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
  }
}

apply plugin: "kotlin-allopen"

allOpen {
  annotation("com.mycompany.myapp.annotation")
}

Second, I generated annotation

package com.mycompany.myapp.annotation
annotation class AllOpenAnnotation

Finally, I added the annotation to Realm model class

@AllOpenAnnotation
class Model {
  var id: Int = -1,
  var title: String = "",
  var desc: String? = null
}: RealmObject()

But the error: cannot inherit from final Model error occurs.

Is there something that I did wrong?

like image 274
mayTree Avatar asked Jan 04 '17 10:01

mayTree


1 Answers

You need to add the name of the annotation to the path in your config file:

allOpen {
    annotation("com.mycompany.myapp.annotation.AllOpenAnnotation")
}
like image 130
marstran Avatar answered Oct 03 '22 10:10

marstran