How to inject into plugin services from BuildSessionScopeServices

Hi,

How to inject into a plugin a service registered within BuildSessionScopeServices? I am in particular interested in ClasspathRegistry - up to Gradle 2.7, I just needed to put @Inject annotation on the plugin class constructor, but with Gradle 2.8 it does not work anymore - I get some other ClasspathRegistry instance from ProjectServices…

Thanks,

Predrag

Anybody has idea? In my plugin I need to get reference to ClassPathRegistry that is injected into DefaultWorkerProcessFactory. There is a hack that to get it via reflection from DefaultWorkerProcessFactory instance injected into Test task.

Just for the record, injecting ClassPathRegistry into plugin constructor was working up to Gradle 2.7 - but it does not work anymore.

This stuff is internal, so may break at any point in time without notice.

What are you using the registry for? There might be a better way to get the data.

I am the author of dockerized test plugin and am in need to replace DefaultWorkerProcessFactory with my custom, but I still need ClassPathRegistry instance injected into the default factory in order to start successfully test worker process. As I have said, up to Gradle 2.7, I could obtain this ClassPathRegistry instance at the plugin construction time, but now (Gradle 2.8) I get some other instance that does not contain WORKER_MAIN classpath.

You can try getting it from the Gradle object’s services…

e.g. project.gradle.services.get(ClassPathRegistry)

I haven’t tested. Let me know.

Hi,

Sorry for the late reply, but unfortunately your idea does not work.

Predrag

Can you elaborate on how it doesn’t work?

The behavior is exactly the same as the injecting an instance of ClassPathRegistry into the plugin constructor. Namely, I get the instance of the registry that does not know about WORKER_MAIN classpath, and therefore it cannot be used for starting test worker JVMs.

Thanks,

Predrag

Luke,

Any more ideas?

Thanks,

Predrag