If I’m in a plugins `apply` method and have access...
# plugin-development
If I’m in a plugins
method and have access to the
. Is there a way I can determine which “target” is being run? Not sure what the correct terminology is, for instance if I have a Project with a load of modules but two modules can be ran as apps. From my plugin which is applied to one of the lower level modules, can I determine which of those two modules was/is the run target?
The question is mostly, why would you need to know that? Can’t you configure the plugin in a way that it doesn’t need to figure out where it’s being run?
Why can't you apply your plugin to the app module? I guess that would fix it
The plugin adds dependencies. For AppA, moduleX needs Y but for AppB moduleX needs Z (and neither can have both)
Perhaps another plugin in the AppA/AppB modules can write to a file declaring its running? And I’d read from that. But not sure that that order is guaranteed (AppA built before moduleX)
Hum...it smells bad IMHO
😬 1
The app itself can add the right dependency, and the modules just need to depend on a module with the interface. (Depending on the case it might be provided through DI)
thats what we do now 👍 hoping/contemplating to break apart the app from being a so central
I was hoping gradle had a way to find out which module “started” the build, because that’ll be the one that is the target right
I guess from the outside I can add an option and pass that to the gradle command
sorry for my hacks 😅
How do you define "started"? Is moduleX a build that AppX and AppY include via composite build? Then you could for example indeed traverse the parent build hierarchy to look which is importing the current project.
But this is at best very bad practice.
Maybe a better solution would be if you have two feature variants in moduleX. Each of the feature variants defines the unique set of dependencies. Both can use the same JAR if it is actually the same code running with these dependencies. Then AppX and AppY can select the variant they need and get the correct dependencies transitively
@Vampire I expect it to be different apps (maybe one is instant app and the other complete, or simply small apps consuming less modules to be used at development)
👆 1
Would that somehow not fit my statement?
@Paul Blundell but think on the obvious, I can run
./gradlew assemble
Not really (I mean, your statement is still right Vampire), they can use "flavors" for that.
ah yes
still needs building without a target ofc thanks