I'm working on a Gradle project that has several modules. The project is implemented in Kotlin. One of these modules is the main entry point to the project, which is the main module. Another module provides a number of utilities to the main module.
My problem is that these utilities module requires some command line arguments. These command line arguments are only available in the main module.
My question is: what would be the best way to pass the data from the main module to the utilities module? The key part is that, these command line arguments initialise an object which is provided through some external library. When the command line arguments are read, an object of this external library is initialised.
I have tried/considered several options:
- Modifying constructors and function definition in both modules to accommodate this new object.
- Create a singleton from this object.
- Create a singleton from this object and wrap in a service. Then use the service locator pattern to find a service.
I think the problem with the last two approaches is that the data which are the command line arguments needs to be saved and retrieved when the singleton object needs to be re-initialised.
TL;DR How do I pass command line arguments from one part of the project to another without modifying constructors or function definitions?
Related I think the posts below explain better what I'm asking in this question, but I'm wondering if there is anything in Java/Kotlin that provides this functionality out of the box, or if there are some examples how to do this.