I have a complex Gradle project with some sub-projects having optional dependencies which are normally not used; I guess this can be modeled by features/capabilities. Among this sub-projects there is a ‘main’ sub-project which has dependencies on other sub-projects. This ‘main’ sub-project has test code which needs optional dependencies to be present in runtime.
How can I enable optional dependencies for ALL sub-projects used in ‘main’, but only for test code? Preferably without copy/pasting all ‘main’ dependencies twice - once for main code and one more time for test code with enabled capability.
By default, when you declare dependency to projectA, you actually declare dependency to the ‘default’ configuration of the projectA. If you need to depend on a specific configuration of projectA, use map notation for projects: configurationName project(path: ':projectA', configuration: 'someOtherConfiguration')
I. Transitive dependencies do not work “out of the box” - in my example ‘:main’ depends on ‘:sub2’, which depends on ‘:sub1’, which has an optional dependency. If I simply add
then optional dependencies from ‘:sub1’ won’t be present.
II. In the example ‘:main’ depends on both ‘:sub2’ and ‘:sub4’, and I don’t want to repeat all these dependencies for testRuntime with optional configuration (and in a real project there are many dependencies). I want some simple switch to enable all optional dependencies at once.