I have 2 projects (call them ProjectA and ProjectB). Both projects depend on a library jar (call it myJar) and ProjectA depends on ProjectB. I have the following in my build.gradle for ProjectA:
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } }
I have something similar for ProjectB without the project dependency. With this setup, when I run a jar task for Project A, gradle also runs the jar task on ProjectB and myJar gets unpacked and packed twice. This is very slow compared to jar creation in ant. Is there a way to improve my jar creation time? Thanks!
Yes, they both depend on myJar. I have other use cases that are more complex than this and keeping track of duplicate dependencies manually is not preferable.
I understand that. As I said before, I have use cases that are more complex and my expectation is that Gradle should be able to recognize when there is this kind of dependency and avoiding unpacking and packing the jar several times. Other build tools like Ant do not have this issue.
In Gradle, a project dependency gets resolved to a dependency on that project’s Jar (at least if the depended-on project has the ‘java’ plugin applied and you haven’t reconfigured its publications). Hence, Gradle is just doing what you are telling it to. One solution is to only create a fat Jar when needed, e.g. when publishing a Jar, and do it in a separate task (e.g. ‘jarAll’).