Today I started building a library for my company so we could avoid some duplicate code across a few of our apps. The library uses a few dependencies that are duplicated in the apps. In this case, Retrofit and Eventbus. Anyhow when I included my library it looked something like this:
implementation (project(":mylib")
Knowing that I would be using Eventbus as well as some other dependencies, I wanted to test exluding them in order to avoid duplicate dependencies. So I added in Eventbus to the app's gradle file and I excluded Eventbus from my library.
implementation 'org.greenrobot:eventbus:3.0.0'
implementation (project(":mylib")){
exclude module: 'eventbus'
}
Now I am fully aware that I could just not include Eventbus in the app by just importing mylib
, and certainly I have excluded dependencies to avoid build conflicts in the past so I am familiar with the usage, but I just wanted to experiment with it because it occurred to me that I really don't know what's happening under the hood with this exclusion. The term exclusion implies (to me) that this dependency isn't compiled period at the point of exclusion, however, this can't be the case because the 3rd party library (Eventbus in this case) still seems to execute just fine in mylib
and if it didn't compile there would be crashing code world wide because of weird library dependency issues. So what exactly is happening here? Is it the case that it still compiles for the library, and it still compiles for the app, but somehow these dependencies are just separated? If so, it seems like that isn't all that efficient because you would still be duplicating all the methods in the project.
Clearly I have a limited knowledge of this, so if someone could clarify this I would very much appreciate it.