0

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?

tmn
  • 11,121
  • 15
  • 56
  • 112

1 Answers1

0

I got some ideas from this post that seemed to work.

jar {
    manifest {
        attributes(
                'Main-Class': 'com.swa.rm.pricing.reporting.ux.SaleMxReportingUI'
        )
    }
}

task fatJar(type: Jar) {
    manifest.from jar.manifest
    classifier = 'all'
    from {
        configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
    } {
        exclude "META-INF/*.SF"
        exclude "META-INF/*.DSA"
        exclude "META-INF/*.RSA"
    }
    with jar
}
Community
  • 1
  • 1
tmn
  • 11,121
  • 15
  • 56
  • 112