What's the recommended way to pass a listener to a...
# community-support
s
What's the recommended way to pass a listener to a shared
BuildService
from the code consuming a plugin? I cannot pass a listener via service parameters, because they have to be
Serializable
, but the listener is not. So far, I haven't found a better way that passing the listener via a singleton object:
Copy code
// Inside the plugin:
object MyListenerHolder {
    var listener: MyListener? = null
}

abstract class MyService : BuildService {
    val logic by lazy {
        Logic(MyListenerHolder.listener)
    }
}

// Consumer code:
plugins.withId("com.myplugin") {
    MyListenerHolder.listenter = MyListenerImpl()
}