I describe a weird behavior in gradle dependency management, where project A refers to project B as a compilation dependency, and to reference library B of project B as a run-time dependency. Now I can use the classes from the C library in my project A.
My question is: (Why) is this a bug or feature?
The problem can be reproduced with gradle 2.9 and 2.10 and the following minimal installation:
// 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 you can see, gradle :A:dependencies shows
[...] compile - Compile classpath for 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 is entirely possible in the Java code residing in project A.
java dependency-management gradle
Michael schaefers
source share