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?
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.
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.