When using a project dependency (with scope compile), Gradle adds the subprojects transitive dependencies as a compile dependency to the project itself.
Here is a sample projects structure:
------------------------------------------------------------
Project :datamodel
------------------------------------------------------------
compile - Dependencies for source set 'main'.
No dependencies
------------------------------------------------------------
Project :backend
------------------------------------------------------------
compile - Dependencies for source set 'main'.
\--- project :datamodel
------------------------------------------------------------
Project :frontend
------------------------------------------------------------
compile - Dependencies for source set 'main'.
\--- project :backend
\--- project :datamodel
I would expect the transitive dependency datamodel to be provided at runtime for the project frontend. Instead it is possible to compile against classes from the datamodel project.
Is this an intended feature? In case it is, can anyone explain why Gradle is setting the scope of transitive dependencies to compile?
To fix this problem, i added dependencies like this:
compile (project(path: ':backend')) {
transitive = false
}
runtime project(path: ':backend', configuration: 'runtime')
Is there any other way to bypass this problem?