I'm seeing a weird error that I cannot figure out....
# plugin-development
k
I'm seeing a weird error that I cannot figure out. Suppose I have this:
Copy code
abstract class MyService : BuildService<BuildServiceParameters.None> {
  abstract val myProperty: NamedDomainObjectContainer<MyType>
}

abstract class MyExtension constructor(val service: Provider<MyService>) {
  val myProperty
    get() = service.get().myProperty
}

override fun apply(project: Project) {
  val service = project.gradle.sharedServices.registerIfAbsent(SERVICE_NAME, MyService::class.java) {}
  val extension = project.extensions.create<MyExtension>(EXTENSION_NAME, service)
  
  extension.myProperty.register(...)
}
I'm seeing a weird
ClassCastException
being emitted from this code:
Copy code
Caused by: java.lang.ClassCastException: MyService$Inject cannot be cast to MyService
The stacktrace seems to be pointing to the
service.get()
call in
MyExtension.myProperty
. Any ideas wrt what is going on?
e
it's probably from a different classloader
is your plugin being loaded in multiple projects without being loaded in a parent (or root) project? if so, that will cause this issue
☝️ 1