java - gradle includes transitive runtime dependency as compile dependency -
i expriencing strange behavior in gradle dependency management, project references project b compile dependency , project b references library c runtime dependency. can use classes library c in project a.
my question: (why) bug or feature?
the problem can reproduced gradle 2.9 , 2.10 , following minimal setup:
// settings.gradle include ':a', ':b'
// build.gradle allprojects { apply plugin: 'java' apply plugin: 'maven' repositories { mavenlocal() mavencentral() } } project(':a') { dependencies { compile project(':b') } } project(':b') { dependencies { runtime "org.slf4j:slf4j-log4j12:1.7.13" } }
as can see, gradle :a:dependencies
shows
[...] compile - compile classpath source set 'main'. \--- project :b \--- org.slf4j:slf4j-log4j12:1.7.13 +--- org.slf4j:slf4j-api:1.7.13 \--- log4j:log4j:1.2.17 [...]
and using log4j totally possible in java code residing in project a.
see this q&a. if don't specify configuration, gradle choose default
configuration extends runtime
. quick fix use
compile project(path: ":b", configuration: "compile")
Comments
Post a Comment