How do I tell Gradle to include a local library jar that in turn has dependencies?

Viewed 2629

I'm surely missing something as I read the Gradle documentation, since this feels like a common use case. Basically, I have two projects - MyApp and MyLib. MyApp will make use of MyLib.jar as a dependency. MyLib, in turn, has its own dependency jars - when built, MyLib's build.gradle specifies these. In the end, MyLib.jar will contain only the non-dependency .class files, so MyApp will somehow need to download MyLib.jar's dependencies at compile-time.

How do I tell MyApp's build.gradle to include MyLib.jar and then download MyLib's dependency jars without specifying those jars in MyApp's build.gradle? I feel like MyApp's build.gradle shouldn't know about transitive dependencies. I understand that normally, build.gradle will look in a remote Maven/Ivy repo and read the corresponding xml to download the appropriate transitive dependencies, but I don't want to upload MyLib to a Maven/Ivy repository. Ideally, I'd like to distribute MyLib.jar alongside some descriptor file - e.g. pom.xml - that lists the transitive dependencies, but not necessarily packaged as a "repository". See the diagram below to see what I'm referring to:

Library jar dependencies

Note that I plan on distributing MyLib.jar, not as a set of sources, but as a closed jar, so I don't want to set up a multi-project Gradle build. Furthermore, MyLib's dependencies may either be found in MavenCentral/etc repositories or as jars alongside MyLib.jar in the filesystem.

1 Answers
Related