Hello guys, I'd like to have a question please. I...
# gradle
s
Hello guys, I'd like to have a question please. I have two modules in a project:
A
and
B
In
A
I declare a dependency on a local
x.aar
archive using the
api
keyword. Now,
A
has access to all classes inside
x.aar
. In
B
I declare a dependency on
A
using the
implementation
keyword, hoping, that I could access classes from
x.aar
. This does not work because
B
says that
x.aar
cannot be found. This can be fixed by adding
repositories
to `B`:
Copy code
repositories {
    flatDir {
        dirs "../libs"
    }
}
Is there any way I can do that without explicitly importing the
x.aar
library in
B
? Summary: I'd like to access an imported library (
.aar
lib) from
A
in
B
without having to import the lib in
B
. Thanks a lot. EDIT: sorry, I meant dependency
B -> A
. Additionally, sorry that this is a general Gradle question.
😶 3
e
repositories are not transitive, you'd best put x.aar into a maven repo that you add by default to all your projects (e.g. with settings.gradle/dependencyResolutionManagement)
v
Assuming you meant you declare a dependency from
B
to
A
, not
B
to
B
, this is quite normal. A consumer of a dependency has to provide all repositories that are necessary to resolve the dependency and all transitive dependencies. If you for example declare a dependency on library X in the Spring Maven repository in
A
and then depend on
A
from
B
without declaring the repository in
B
too, you also miss that dependency. Repositories configuration never propagates and that is also important, as for example some company guidelines require that all dependencies come from some internal repository and so on. I usually only declare the repositories for all projects in the settings script and even disallow declaring additional repositories in projects, that way all projects share the same repository declarations.
s
Thanks a lot, both of you. @Vampire thanks for the detailed answer, I did not really know that repository configurations should/are not be propagated. Your explanation is awesome, I really appreciate it. I will be able to resolve my problem now. Thanks!