Kotlin extension functions visibility in multi module environment


Starting with Gradle 3.0 you are able to limit the scope of dependencies to the module by using ‘implementation’ keyword.

It works fine, but I’ve noticed that if the dependency is a kind of a kotlin extensions (which is a set of kotlin extensions functions), it is leaked to the other modules.

If module A uses module B:
implementation project(path: ':B')

and module B uses extension functions library
implementation "com.example.some-extensions"

then all of the extension functions are visible in module A.
Is there a way to prevent leaking this kind of dependencies to outer modules?


As I understand this is intended behaviour. If however you would have a module C that uses A, it will not see the definitions from B.


Thanks for the response!

It turns out that gradle’s 'implementation' works as intended.
The problem is that Android Studio ‘sees’ all the dependencies from the submodules.

In other words, if you have a project structure like this:
App(application) > B(lib) > C(lib)

App’s gradle: implementation project(path: ':B')
B’s gradle: implementation project(path: ':C')
C’s gradle: implementation 'com.example.some-lib'

then you can ‘use’ some-lib’s classes in B as well as in App and IDE won’t complain and add required imports.
The project will eventually fail when you build it and get errors that some dependencies are not resolved.