Run shadowed jar with classpath of an excluded dependency jar


(GradleFreund) #1

Hello gradle friends,

i have the requirement to run a fat jar created with the gradle shadow plugin (https://github.com/johnrengelman/shadow).

I have a dependency that should not be flattened into the shadowed jar but must be part of the classpath during runtime.

I made a little example with the scenario. My problem is that the main class still throws an ClassNotFoundException when i run the fat jar with: gradle runShadow

buildscript {
    repositories { jcenter() }
    dependencies {
        classpath('com.github.jengelman.gradle.plugins:shadow:1.2.3')
    }
}

apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'application'

repositories { jcenter() }

mainClassName = "Starter"

dependencies {
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
}

jar {
    baseName = 'fat-tony'
    manifest {
        attributes 'Main-Class': "java:Starter"
    }
}

shadowJar {
    baseName = 'fat-tony'
    classifier = ''

    // this jar is signed and can not be used outside this signed container
    dependencies { exclude(dependency('org.apache.commons:commons-lang3:3.0')) }
}

runShadow { // this task extends JavaExec and is provided by the shadow plugin

    // put the excluded jar in the classpath. is that correct?
    classpath = configurations.compile 
}

(GradleFreund) #2

Hi, i am a gradle beginner so is the idea behind my approach completely wrong? Could someone help me with that?