In a build.gradle
script, I would perform the following task to include dependencies into a runnable application JAR file.
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'org.somepackage.MyMainClass'
)
}
from configurations.compile.collect { entry -> zipTree(entry) }
}
However, in multi-project setups I was missing some dependencies in the JAR file. I ultimately discovered any dependencies specified in other project build.gradle
scripts were not being included, unless the parent project had those dependencies too.
For example, Project A depends on Project B. Project B uses Google Guava. When I deployed Project A to a runnable JAR file, Google Guava would not be included and there would be runtime errors. If Project A redundantly specified Google Guava in its build.gradle
script, then it runs just fine.
How can I modify my jar
task above to include dependencies in multi-project setups?