ShadowJar and Application Plugin

Hi folks,

First-time poster here!

I have been trying to add support for shadow jars (FAT jars) to the existing grpc-java-examples gradle script without much success. Here is the path to the existing gradle file.

All I want is to add support for creating standalone/FAT jars and ensure that the distribution runnable scripts use the FAT jars instead of the list of all dependencies separately.

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

task clientFatJar(type: ShadowJar) {
    classifier = "client"
    configurations = [  project.configurations.compile ]
    from sourceSets.main.output
    manifest {
        attributes("Main-Class": 'io.grpc.examples.helloworld.HelloWorldClient')

task helloWorldClient(type: CreateStartScripts) {
  mainClassName = 'io.grpc.examples.helloworld.HelloWorldClient'
  applicationName = 'hello-world-client'
  outputDir = new File(project.buildDir, 'tmp')
  //classpath = jar.outputs.files + project.configurations.runtime
  classpath = clientFatJar.outputs.files

applicationDistribution.into('bin') {
  fileMode = 0755

The above modification works, kind of, in the sense that I can get the startup script to include the classpath as set CLASSPATH=%APP_HOME%\lib\examples-client.jar i.e. the fat JAR but the script doesn’t work because my install/lib directory doesn’t include the shadow jars.

I feel that this can be solved by tweaking the applicationDistribution task but unfortunately I can’t seem to get enough out of the documentation to make that change.

Would someoen please help me out here?

Any help on this please? To put it simply, is there a way to get custom ‘shadowjar’ and ‘application’ plugin tasks to play nice with each other i.e. to make sure that installDist task copies the FAT jar to the lib directory instead of all the dependencies separately?

If I understood you correctly, you can do this using gradlew installShadowDist which will produce a single jar in /build/install/yourProject/lib.

To customize what goes into build/install/yourProject, you’ll want to have your own distribution. For example:

distributions {
    myCustomDistribution {
        baseName = 'myProject'
        contents {
            from { 'src/readme' }
            from(shadowJar) {
                into "lib"