Inheriting Dependencies from Referenced Projects

I have a build with several projects specified as dependencies that are relative on the filesystem. The dependency tree is something like

core <- utils <- my project

The “core” project has a dependency on log4j, so I specified it accordingly in the build.gradle of “core”. While building “my project” I noticed that I was getting many errors claiming that methods from log4j can’t be found.

error: cannot find symbol
            if (logger.isTraceEnabled()) {
 method isTraceEnabled()
  location: variable logger of type Logger

I thought this was strange so I checked my dependencies using “gradle dependencies” which showed the following:

compile - Compile classpath for source set 'main'.
+--- project :utils
  +--- project :core
  +--- log4j:log4j:1.2.17
  ... A great many other dependencies
  \--- org.apache.commons:commons-math:2.1
+--- project :core (*)
... other deps
\--- net.sf.opencsv:opencsv:2.3

So it appears that log4j is in the compile classpath, but is somehow not being picked up in the subproject “my project”. If I add log4j to the dependency list for “my project” explicity then everything works. My initial thinking was that I should define my dependency on the project using the transitive flag, but I wasn’t able to get that working correctly. Does anyone have any suggestions on how to get “my project” to recognize the dependency durther down the hierarchy?

This looks like like you have multiple versions of log4j on your classpath. You’ll notice it can find the ‘Logger’ class, just not the particular method ‘isTraceEnabled()’. I’d see what all log4j related libraries are being brought in.

gradle dependencyInsight --dependency log4j