Runtime dependency of a dependency not downloaded

I have a library, we’ll call it library-a. It’s similar to slf4j in that it has implementations stored in other projects/libraries. Let’s call one of those library-b.

In library-a, I have the following build.gradle snippet:

dependencies {
  runtime group: "org.other", name: "stuff-this-library-needs", version: "3.4.5"
}

In library-b, I have:

dependencies {
  runtime group: "com.my.somegroup", name: "library-a", version: "1.2.3"
}

In a test project, I have

dependencies {
  runtime group: "com.my.somegroup", name: "library-b", version: "1.2.3"
}

When I run the test project, I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/other/stuff/this/library/needs/SomeClass

I’ve tried:

  • Using runtime instead of compile
    • Then it doesn’t compile, even though the docs say:

      runtime - The dependencies required by the production classes at runtime. By default, also includes the compile time dependencies.

  • Using compile and runtime
    • It seems to compile here, but I still get the NoClassDefFoundError

I’m assuming there’s something about how gradle handles dependencies I’m misunderstanding. Do you know how I can make a library that depends on another library using gradle? To be more clear, I need the stuff-this-library-needs dependency in library-a and library-b, but not the test project.

So does the ‘test’ project simply need to exclude this dependency? Where should the class that it is complaining about come from? Perhaps you simply need to add that as a runtime dependency. As I interoperate the samples you have provided both ‘stuff-this-library-needs’, ‘library-a’ and ‘library-b’ will be on the runtime classpath for ‘test’. You should also be able to confirm this via gradle dependencies --configuration runtime.

Here’s how I’d like the dependencies to work:

stuff-this-library-needs <-requires- library-a <-requires- library-b <-requires- test-project

I’m not looking to exclude the stuff-this-library-needs from the test-project, I just don’t want to have to care about it (so it should be a transitive dependency). I’ve been reading through the docs. Still no luck there, but I have lots more to go through (there’s a lot of gradle history woven in there between the user docs).

Thanks for taking a look!

A co-worker helped me figure it out with gradle dependencies. I was missing the maven repos. I’d removed this to figure out why it wasn’t downloading the library I’d uploaded to our internal nexus. Turned out it was uploading those jars, they were just empty because I was using Eclipse’s src/ folder instead of gradle’s src/main/java convention. <3 convention over configuration, especially w/the error reporting.

Anyway sorry to waste your time, and thanks for taking a look.