How to get file path to binary JAR produced by another subproject?

(Marcin Zajączkowski) #1

Quick question: How to get file path to binary JAR with classes produced by another subproject?

Longer version: Multi-project build. Subproject ‘App’ depends in subproject ‘Shared’. In my plugin I need get access to compiled classes from ‘Shared’ used in ‘App’ module. Initially I just used:


but I spotted that Gradle creates a JAR file and uses it as a dependency. So I need to take that JAR use a reference to it (e.g. as ‘File’) to do processing. How can I do that?

(Mark Viera) #2

A project dependency is effectively a dependency on a file (or collection of files). If the project you depend on is a Java project, then in that case you are already describing a dependency to the JAR. In order to isolate the artifact dependency it’s often convenient to create a ‘Configuration’ for that one dependency.

configurations {

foo {

transitive false



dependencies {

foo project(’:shared’)


Then you can access the JAR through the configuration.

(Marcin Zajączkowski) #3

I hoped for something simpler, but in the end that solves my problem. Thanks Mark.

(Marcin Zajączkowski) #4

Accidentally I have found one more solution which works:


It is less flexible, but in many cases it should give the same result. WDYT?

(Mark Viera) #5

In general you should use project dependencies to convey dependencies across projects. Dependencies to individual project tasks is typically more brittle and doesn’t necessarily properly describe the “output” of that project.