I’d like to implement a Gradle (object) plugin which can be applied to multiple subprojects and at the same time share a global resource between all instances of the plugin.
The use case is to access another tool via its REST API and to use a shared HTTP connection pool for more efficiency and to be able to better control how many simultaneous connections may hit the API in the face of parallel builds. From my research so far a typical solution seems to be to attach the shared resource (i.e. the HTTP client pool) as a property to the root project exactly once and pick it up from there if it already exists.
Is this a reasonable solution or is there a better way to share global resources for the whole build? Is there an existing way to do something like a “create if not exists” atomically for project properties to ensure atomicity even in parallel builds? Or can I use the common Java synchronization primitives and synchronize for example on the root project object to ensure that a property is only created exactly once?
Thx for your help!